Completely disconnect logs from XCGLogger during production

How to completely disable logs from XCGLogger in a production environment?

I am currently using logLevel = .None .

Is this the recommended way?

+6
source share
1 answer

This is one of the possible ways, but not ideal.

Firstly, I would think if you really want to completely disable logs in production. Using error and severe logs can be a useful diagnostic tool for released applications.

If you still want to completely exclude magazines in production, I would recommend changing the setup method and using a registrar than what I have in the official documents.

Change the global log object instead:

 let log: XCGLogger? = { #if DEBUG let log = XCGLogger.defaultInstance() log.setup(.Debug, showThreadName: true, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: nil, fileLogLevel: .Debug) return log #else return nil #endif } 

Then change your boolean calls to:

 log?.debug("whatever") 

This will eliminate any logger overhead since log will be nil in production and no log calls will ever be made.

+8
source

All Articles