How do I completely disable logs from XCGLogger when in production environment?
At present I am using logLevel = .None
.
Is this the recommended way ?
That's one possible way, but not ideal.
First, I'd wonder if you really want to completely disable logs in production. using error
and severe
logs can be useful diagnostic tools for released apps.
If you do however want to completely eliminate logs in production, I would recommend altering the way you set up and use the logger than what I have in the official docs.
Change the global log object to be an optional 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 log calls to:
log?.debug("whatever")
This will eliminate any overhead of the logger since log
will be nil
in production and no logging calls will ever be made.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With