Skip to content

Capturing system log messages inline with DDLog messages #168

Open
adamgit opened this Issue Nov 15, 2013 · 13 comments

4 participants

@adamgit
adamgit commented Nov 15, 2013

Sometimes, you need more than the app's messages. For instance, we have a bug in a 3rdparty hardware accessory for iPhone which is crashing the OS (!) with a kernel panic.

(NB: a side-effect of this is that iOS wipes the system logs, when it reboots)

Lumberjack is great for capturing the logs to a large file in parallel, so that we can still read them even after a reboot. This is good.

However, we need to capture the OS messages leading up to the kernel panic (from what I've seen, I suspect an Apple daemon probably spews something very helpful just before the crash)

Pre-Lumberjack, I'd do pipes of stderr and stdout, at the process-level, into memory, and then save those messages out to file. With LJ, I'm not sure how to do this - it's not mentioned in the FAQs, but it seems a pretty important thing?

Obviously, I don't want to re-write the entirtey of log-rotation, management, etc. And if I did, it would be unhelpful to have two streams of logfiles. I'd like to get stderr/out redirected into the same stream DDLog is outputing.

Is this possible today? If so, what do I need to do?

If not ... please make this a feature request ;).

@adamgit
adamgit commented Nov 17, 2013

Update: Apple has now banned developers from doing this :(. It is impossible in iOS7 onwards without jailbreaking your phone. This is IMHO stupid and foolish.

I'd be interested in answers/input/advice to the original question, because it's still valid with iOS6, but ... until Apple stops messing developers around, it's irrelevant going forwards :(

@bpoplauschi
CocoaLumberjack member

@adamgit you raised a good discussion, as an option to capture system logs would be quite nice. The issue I see is: building a feature that doesn't work on all supported OS versions and worst, doesn't work on the latest OS version can generate confusion, not to mention the extra complexity. We can only play by Apple's rules and in this case, I think it's clear they don't encourage people in doing this.

@rivera-ernesto
CocoaLumberjack member

From Apple's documentation it sounds like one could redirect ASL's output:

NSLogv
Logs an error message to the Apple System Log facility.

void NSLogv (
NSString *format,
va_list args
);
Discussion
Logs an error message to the Apple System Log facility (see man 3 asl). If the STDERR_FILENO file descriptor has been redirected away from the default or is going to a tty, it will also be written there. If you want to direct output elsewhere, you need to use a custom logging facility.

Where's the banned notice?

@adamgit
@rivera-ernesto
CocoaLumberjack member

Still can't find any of that Apple's documentation.

You could try to implement it for iOS 6 to give it a try, even if the method doesn't work for iOS 7 we could learn something and then try to work it around.

@adamgit
@rivera-ernesto
CocoaLumberjack member

As it's impossible to have every feature on every system version anyway, I think it would be ok to implement this for < iOS 7 if someone wants to do a pull request and it's clean.

Also supporting the less restrictive OS X would be a good incentive to do it.

@hyling
hyling commented Mar 3, 2016

I think this is still useful for capturing logs from libraries I'm using that don't use CocoaLumberjack. This this feature ever get added?

@rivera-ernesto rivera-ernesto reopened this Mar 4, 2016
@hyling
hyling commented Mar 4, 2016

The way the ASL works is you have to poll it and get all messages that occurred between time X and Y. Does CocoaLumberjack add a timestamp to all entries so I can insert the messages at the correct place in the CocoaLumberjack stream?

@rivera-ernesto
CocoaLumberjack member

I think it does. You should give it a try to be sure.

@hyling
hyling commented Mar 4, 2016

I'm not familiar with the CocoaLumberjack codebase, hints as to here to look to insert into the stream?

@rivera-ernesto
CocoaLumberjack member

Check DDLogMessage properties. I think there is a timestamp. Then check where it is set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.