首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在每个记录的行前重复"XCGLogger writing to“

在每个记录的行前重复"XCGLogger writing to“
EN

Stack Overflow用户
提问于 2016-12-16 05:44:46
回答 1查看 257关注 0票数 1

以前XCGLogger对我来说运行得很好,但我决定尝试一些更高级的功能。现在,我在Xcode的控制台视图中的日志输出中填充了:

XCGLogger writing log to: <my logfile name>

它会出现在每条记录的消息之前。你知道为什么吗?

我的XCGLogger设置:

代码语言:javascript
复制
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
}
EN

回答 1

Stack Overflow用户

发布于 2016-12-16 06:03:11

修复了!我会告诉你我做错了什么。有关更正后的代码块,请参阅底部。

首先,在设置log变量时,我在声明中省略了=符号:

let log : XCGLogger {

并且忽略了将()添加到块的末尾。

然后,我收到来自编译器的错误消息,指出:

'let' declarations cannot be computed properties

我想也许在Swift 3.0中有一些我没有意识到的变化,所以我把它从let改成了var,然后继续,意思是稍后再来讨论这个问题。当然,我忘了。

然后我经历了上面解释的问题,在这里发帖后,再次浏览了所有内容,并意识到每次都会出现该消息的唯一方法是每次我登录时都会以某种方式初始化它。哦!现在,我记起了有关“计算的属性”的警告,并最终意识到每次访问log变量时,我的代码都在运行所有的日志初始化。

一旦我返回并将=()添加到log的声明中,并将其切换回let,一切都按预期工作:

代码语言:javascript
复制
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
}()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41173826

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档