Cocoalumberjack: What is the correct setup to initialise CocoaLumberjack now for all versions of iOS up to iOS11

Created on 6 Dec 2017  路  6Comments  路  Source: CocoaLumberjack/CocoaLumberjack

All the current documentation for CocoaLumberjack that i've found still recommends using the same loggers I've used since using it a few years ago, namely

DDLog.add(DDTTYLogger.sharedInstance) // TTY = Xcode console DDLog.add(DDASLLogger.sharedInstance) // ASL = Apple System Logs

I happened to notice in my current app that I was getting two logs output for every log I called, and did some searching to find the following discussions

https://github.com/CocoaLumberjack/CocoaLumberjack/issues/685
https://github.com/CocoaLumberjack/CocoaLumberjack/issues/765
https://github.com/CocoaLumberjack/CocoaLumberjack/issues/858

These are all quite old but had good advice that it was the two loggers that may cause issues, though there seems to be some debate as to what version of iOS you're using, whether its in the simulator etc. For what its worth I was seeing the double logging on the simulator in my case.

I've commented out the TTY logger and am left with just

DDLog.add(DDASLLogger.sharedInstance)

for now, which has fixed my double logging in the simulator targeting iOS11.

The last issue referenced above talks about ASL Depreciation warnings, which I've not noticed but i guess suggests I've gone for the wrong option. Beyond that within that issue someone recommends actually using

I recommend you use DDOSLogger instead of DDASLLogger with iOS 10+, macOS 10.12+, tvOS 10.0+, or watchOS 3.0+. You can use it from CocoaLumberjack 3.2.0.

Which sounds interesting again, though seemingly with caveats on versions of Cocoalumberjack and iOS.

I guess I'm looking for an authoritative answer to be put in the documentation, or at least some notes towards the fact that the current advice doesn't seem to be correct anymore. Perhaps the solution is complex but having a suggestion or guidance on the recommended approach for this would be great to see.

Basically, what is the right way to configure CocoaLumberjack right now?

Thanks for your time

Cheers

Most helpful comment

While still waiting for somebody authoritative, will try to help as much as I can.

1) DDOSLogger works around os_log available since iOS 10.0, which supersedes ASL (Apple System Logger) and the Syslog APIs (https://developer.apple.com/documentation/os/logging). Modern logging system (os_log-based) manages not only console logging, but storing logs in memory buffers, purging them and so on. CocoaLumberjack's implementation is smth like: if @available(iOS 10.0, ...) os_log(), so it should be used since iOS 10.0 (it will do nothing on lower versions - no logging, no warnings about it).

2) DDASLLogger worked with ASL, using asl_... C-functions. Deprecated since 10.0 (as mentioned above).

3) DDTTYLogger logged to stderr using writev(STDERR_FILENO, ...). It was some sort of classic logging from the world of ANSI-C and one of its main "killer" features was console log coloring (after https://github.com/robbiehanson/XcodeColors plugin installed). For now - there is no more plugins since Xcode 8 and so there are problems with console coloring (see Issues for that library and similar ones, the only thing I found is attempt to use emoji instead of colors - https://github.com/hemangshah/printer).

Finally, I think you should do something like:

if @available(iOS 10.0, ...) {
  DDLog.add(DDOSLogger.sharedInstance)
} else {
  DDLog.add(DDTTYLogger.sharedInstance)
  DDLog.add(DDASLLogger.sharedInstance)
}

All 6 comments

While still waiting for somebody authoritative, will try to help as much as I can.

1) DDOSLogger works around os_log available since iOS 10.0, which supersedes ASL (Apple System Logger) and the Syslog APIs (https://developer.apple.com/documentation/os/logging). Modern logging system (os_log-based) manages not only console logging, but storing logs in memory buffers, purging them and so on. CocoaLumberjack's implementation is smth like: if @available(iOS 10.0, ...) os_log(), so it should be used since iOS 10.0 (it will do nothing on lower versions - no logging, no warnings about it).

2) DDASLLogger worked with ASL, using asl_... C-functions. Deprecated since 10.0 (as mentioned above).

3) DDTTYLogger logged to stderr using writev(STDERR_FILENO, ...). It was some sort of classic logging from the world of ANSI-C and one of its main "killer" features was console log coloring (after https://github.com/robbiehanson/XcodeColors plugin installed). For now - there is no more plugins since Xcode 8 and so there are problems with console coloring (see Issues for that library and similar ones, the only thing I found is attempt to use emoji instead of colors - https://github.com/hemangshah/printer).

Finally, I think you should do something like:

if @available(iOS 10.0, ...) {
  DDLog.add(DDOSLogger.sharedInstance)
} else {
  DDLog.add(DDTTYLogger.sharedInstance)
  DDLog.add(DDASLLogger.sharedInstance)
}

Thanks for the reply, sorry for my delayed response. My app is working fine, I guess I was just looking for more of an official suggestion on how things should be setup to be updated in the official documentation. Your explanation here is helpful, even having that or some similar discussion on there would be an improvement.

Cheers

Hi guys and thanks for the interest you take in this project.
This issue was long due a response.
As @kpower said, the recommended way would be to just use the DDOSLogger which is available on all platforms.
We also need to update our documentation about this, since it's not clear anymore. I will leave this issue open until we get to it.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

I think the current documentation is better about this subject (DDOSLogger vs DDTTYLogger + DDASLLogger). Closing. Feel free to comment / propose any other improvements to docs/examples

Based on this conversation and others I've ended up with the following initalisation code (objc). (My app supports iOS 9.3+)

// setup CocoaLumberjack loggers
    if (@available(iOS 10.0, *)) {
        [DDLog addLogger:[DDOSLogger sharedInstance]]; // Modern logging works on iOS 10+
    } else {
        [DDLog addLogger:[DDASLLogger sharedInstance]]; // ASL = Apple System Logs
#if !TARGET_IPHONE_SIMULATOR
        // When running on the simulator ASL logs are forwarded to the TTY logger however when run on a device they're not
        [DDLog addLogger:[DDTTYLogger sharedInstance]]; // TTY = Xcode console
#endif
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

trvslhlt picture trvslhlt  路  7Comments

mrinalsymc picture mrinalsymc  路  13Comments

minglini picture minglini  路  4Comments

levey picture levey  路  5Comments

Diarrhio picture Diarrhio  路  5Comments