2016-12-15 6 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

!私が間違っていたことを私はあなたを歩いていきます。修正されたコードブロックについては、下を参照してください。

let log : XCGLogger {

とブロックの終わりに()を追加することを怠っ:log変数を設定するとき

はまず、私は宣言で=記号を残しました。

私はその後を示す、コンパイラからエラーを受け取った:、私は多分、私は知らなかったスウィフト3.0に変更何かを考えたので、私はletからvarにそれを変更し、続け

'let' declarations cannot be computed properties

を後でこの問題に戻ることを意味します。もちろん、私は忘れてしまった。

私は上で説明した問題を経験し、ここに投稿した後、再びすべてを歩き、毎回ログに記録されるたびにメッセージが何らかの形で初期化されていた可能性があることを認識しました。 D'oh!今、私は "計算されたプロパティ"についての警告を思い出し、log変数にアクセスするたびに私のコードがすべてのログの初期化を実行していることに気付きました。

私は戻って、=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 
}() 
関連する問題