我想在我所有的日志中添加一个前缀。我试图子类XCGLogger来覆盖logln(...)或debug(...)函数。
但是我在使用这个的时候面临两个困难

谢谢
发布于 2016-09-19 11:06:30
好吧我找到了。我们需要定义一个符合class或struct的LogFormatterProtocol,并实现format(logDetails: inout LogDetails, message: inout String) -> String函数来修改inout消息。然后创建该类或结构的实例,并将其添加到目标格式化程序数组中:
let consoleDest = ConsoleDestination(owner: myLogger, identifier: "") // myLogger is an instance of XCGLogger
consoleDest.formatters = [MyFormatter()] // MyFormatter is a struct conforming to LogFormatterProtocol
myLogger.add(destination: consoleDest)发布于 2016-09-20 08:44:59
您在上面的代码中遇到的问题是,您对编译器不清楚您正在调用哪个super.logln方法。由于该方法有多个版本,具有不同的函数,其中有些函数具有默认值,因此需要显式地包含足够的参数,以便编译器知道您正在调用哪个版本。这就是为什么你的错误信息说“模棱两可”
https://stackoverflow.com/questions/39570842
复制相似问题