I want to use XCGLogger inside of a Swift framework I'm writing. The app that includes this framework may or may not use XCGLogger as well.
What's the best way to approach this sort of scenario? Would I use something like dependency injection to let the app send the XCGLogger instance to the framework? Where in the framework would I call XCGLogger's setup method?
I'm able to use the same logger in the project and a framework by simply referencing the same XCGLogger.defaultInstance()
in both.
First, import XCGLogger
in the imports, Then instantiate the log instance in the project using let log = XCGLogger.defaultInstance()
.
After that I instantiate the sharedInstance
of the framework I'm using (per my particular use case).
Within the framework, import XCGLogger
& instantiate the logger let log = XCGLogger.defaultInstance()
before my Class
declarations.
Then, back in didFinishLaunchingWithOptions
of AppDelegate.swift
, I do the log.setup(...your params...)
.
In the case of you authoring the framework, you'll want some logic and readme notes to setup the logger if one isn't setup the way you prefer.
Probably not the most elegant way to get it done, but it does work.
Hope that helps.
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