I'd like to give control to the app developer that uses my library to select which level of logs they'd like to see from my lib (e.g. do they want to see all debug messages or just errors).
I know there are filtering controls that Xcode gives us, but I'm wondering if there is a way to pull this off with code. Ideally the user callsite would look like MyLib(logLevel: .info)
.
And then I would pass that info
level somehow to OSLog. Today, I create my logger like this:
let myLogger = Logger(
subsystem: Bundle.main.bundleIdentifier ?? "UnknownApp",
category: "MyLibrary"
)
As far as I can tell, there is nothing I can then pass to my myLogger
instance to configure the threshold level. I'm imagining an interface like:
myLogger.logLevel(.warning)
// Later...
myLogger.debug("You won't see this")
myLogger.error("But you will see this")
Does OSLog and friends give us any ability to do this out of the box, or are we building little wrappers around OSLog to accomplish this?
Thank you, Lou