Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lumberjack 2.0 logger with Swift

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:

  • I added Lumberjack with Cocoapods;
  • I added "#import " to the Bridging-Header file.

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!

like image 844
user3742622 Avatar asked Mar 28 '15 08:03

user3742622


2 Answers

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
    }
}
like image 56
shri Avatar answered Oct 17 '22 16:10

shri


If you're installing using CocoaPods, use CocoaLumberjack/Swift instead of CocoaLumberjack, like so:

pod 'CocoaLumberjack/Swift'
like image 1
Dov Avatar answered Oct 17 '22 16:10

Dov