Lumberjack 2.0 logger with Swift
Asked Answered
V

2

7

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!

Vicarage answered 28/3, 2015 at 8:56 Comment(1)
Until we release 2.1.0 with full Swift support and documentation, please take a look at github.com/CocoaLumberjack/CocoaLumberjack/issues/405 and at the iOSSwift demo from the Lumberjack Desktop projectImperfect
G
1

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
    }
}
Geoid answered 11/11, 2015 at 10:36 Comment(0)
Y
1

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

pod 'CocoaLumberjack/Swift'
Yetty answered 29/12, 2015 at 20:23 Comment(1)
can I then use it with Swift_and_ Objective-C?Babblement

© 2022 - 2024 — McMap. All rights reserved.