2016-12-15 59 views
1

以前,XCGLogger对我来说工作正常,但我决定尝试一些更高级的功能。现在,在Xcode的控制台视图我的日志输出填充:“XCGLogger写入日志”在每个记录行前重复

XCGLogger writing log to: <my logfile name>

它出现的每个记录消息之前。任何想法为什么?

我对XCGLogger设置:

var log : XCGLogger { 
    let log = XCGLogger(identifier: "advancedLogger", includeDefaultDestinations: false) 

    let fileDestination = FileDestination(writeToFile: Constants.file.debugging, identifier: "advancedLogger.fileDestination") 

    fileDestination.showLogIdentifier = false 
    fileDestination.showFunctionName = true 
    fileDestination.showThreadName = false 
    fileDestination.showLevel = false 
    fileDestination.showFileName = true 
    fileDestination.showLineNumber = true 
    fileDestination.showDate = true 

    #if DEBUG 

     fileDestination.outputLevel = .verbose 

    #else 

     fileDestination.outputLevel = .debug 

     // don't log on main thread in production 
     fileDestination.logQueue = XCGLogger.logQueue 

    #endif 

    // Add the destination to the logger 
    log.add(destination: fileDestination) 

    return log 
} 

回答

1

固定!我会告诉你我做错了什么。查看修正的代码块的底部。

首先,建立log变量时,我离开了在声明等号(=):

let log : XCGLogger {

和忽略添加()到块的末尾。

然后我从编译器收到一个错误,指出:

'let' declarations cannot be computed properties

我想,也许东西雨燕3.0,我是不知道的变化,所以我改变了它从letvar和持续,这意味着稍后再回到这个问题。当然,我忘了。

然后我遇到了上面解释的问题,在这里发布之后,再次走过一遍,意识到每次发送消息的唯一方式就是每次登录时它都以某种方式被初始化。 D'哦!现在我想起了关于“计算属性”的警告,并最终意识到我的代码每次访问变量时都运行了所有日志初始化。

一旦我回去,并添加了=()的声明log,并切换回let,一切都会按计划:

let log : XCGLogger = { 
    let log = XCGLogger(identifier: "advancedLogger", includeDefaultDestinations: false) 

    let fileDestination = FileDestination(writeToFile: Constants.file.debugging, identifier: "advancedLogger.fileDestination") 

    fileDestination.showLogIdentifier = false 
    fileDestination.showFunctionName = true 
    fileDestination.showThreadName = false 
    fileDestination.showLevel = false 
    fileDestination.showFileName = true 
    fileDestination.showLineNumber = true 
    fileDestination.showDate = true 

    #if DEBUG 

     fileDestination.outputLevel = .verbose 

    #else 

     fileDestination.outputLevel = .debug 

     // don't log on main thread in production 
     fileDestination.logQueue = XCGLogger.logQueue 

    #endif 

    // Add the destination to the logger 
    log.add(destination: fileDestination) 

    return log 
}()