I used to use Lumberjack logger with Objective C and I like it. Now I start learning Swift and I cannot use my favourite logger there. Could somebody write step-by-step how I can do it please? I try to find something here but all topics are old with custom wrappers, before Lumberjack 2.0 release. What I did:
And I don't know what should I do next? Because in ObjC I had macros: static const int ddLogLevel = LOG_LEVEL_INFO; else static const int ddLogLevel = LOG_LEVEL_VERBOSE; and my log level depends on compile flag... Can I do it here? And how to use Lumberjack in code? Thank you!
Please refer to the below issue on GitHub, as it explains how resolve the issues while integrating the framework for Swift. Also, you can refer to the below example (taken from the issue thread), which is very helpful.
https://github.com/CocoaLumberjack/CocoaLumberjack/issues/405
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let formatter = Formatter()
DDTTYLogger.sharedInstance().logFormatter = formatter
DDLog.addLogger(DDTTYLogger.sharedInstance())
DDLogVerbose("Verbose");
DDLogDebug("Debug");
DDLogInfo("Info");
DDLogWarn("Warn");
DDLogError("Error");
printSomething()
defaultDebugLevel = ddloglevel
printSomething()
return true
}
}
If you're installing using CocoaPods, use CocoaLumberjack/Swift
instead of CocoaLumberjack
, like so:
pod 'CocoaLumberjack/Swift'
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