I'm here for clarity. I'm trying to wrap my head around Apple's Unified Logging. I found a tutorial that explains how to access the logs via console. I understand that debug and info messages are only kept in memory and only displayed in the debug console in Xcode during development (I still don't know the difference between info and debug messages as they appear to be the same to me).
I would like to extend the Logger class to account for a "debugLevel" to determine what is logged to my Xcode debugging console while developing, but also to use in production by allowing the user to select, via a preference setting, the debugging level for the app. For example:
debugLevel 0 = (Development) no logging will occur - no messages will be displayed in the Xcode debugger console debugLevel 1 = (Development) only debug (level 1) entries will be displayed in the Xcode debugger console debugLevel 2 = (Development) both debug (levels 1 and 2) entries will be displayed in the Xcode debugger console debugLevel 3 = (Development) in addition to levels 1 and 2, inner method debug logging (level 3) will be displayed in the Xcode debugger console
I feel these three levels would be sufficient because anything marked with critical, error, fault, and notice are always displayed and logged and I will not be filling up my logs with debugging information by keeping my entries at the debug level.
For production I would use an additional three levels, so the user could turn on debug logging in order to track down an issue they may have by having the debug messages logged to the console as notices, which could then be sent to me for review.
debugLevel 0 = (Production) no debug messages logged debugLevel 4 = (Production) convert all level 1 debug entries to "notices" to be logged to the console debugLevel 5 = (Production) convert all level 1 and 2 debug entries to "notices" to be logged to the console debugLevel 6 = (Production) convert all level 1, 2, and 3 debug entries to "notices" to be logged to the console
With this, my intention is to make a level 1 debug log entry at the top of each method and then a level 2 method exit debug log entry, and all inner method debug log entries as level 3 so the logging can be somewhat controlled. Of course, critical parts of the code have logger.error, logger.critical, etc., etc., which will always be logged since those persist.
I'm sure this isn't the most efficient, if not the improper, way of doing this. Am I understanding the Unified Logging system correctly? Is there a better way of skinning this cat?
SPONSORED Want to try Swift on microcontrollers? MadMachine provides ways to interact with the physical world in a Swift way. Join us and have fun!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.