I am attempting to find a logging framework for a Cocoa application, written in ObjC.
What I've attempted so far:
What l logging framework setup can I use to have ALL messages logged through that framework in a convenient fashion so that if there is a problem with an application, a developer can get the log files, and figure out what went wrong?
I don't want to simply redirect stderr, I want to have a structured log output that contains all of the logs. I don't want some logs going to standard output, I don't want any logs sent to a syslogd, I just want all the logs written to a single file, that reliably identifies all the pertinent information about that log message (such as thread ID, message, the function that called the logger, etcetera), in format that is easy to view and visualise.
What I want is to redirect all current logs to the new destination.
Does anyone have any suggestions?
EDIT:
Effectively, what I want to do, in ObjC terms is:
You can intercept NSLog()
messages (but not ASL in general) using _NSSetLogCStringFunction()
. It’s documented here for WebObjects 4 for Windows, but it exists in current Mac OS and iOS releases too. However, it’s a private function that may go away at any time, so you shouldn’t rely on it in released code.
If you want to be able to safely do this for non-debug builds, I suggest duplicating this enhancement request on Radar.
You can use the Foundation function NSSetUncaughtExceptionHandler
to set a callback function that will handle all uncaught exceptions:
void CustomLogger(NSString *format, ...) {
//do other awesome logging stuff here...
}
void uncaughtExceptionHandler(NSException *exception) {
//do something useful, like this:
CustomLogger(@"%@", [exception reason]);
}
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
For NSLog
, you can use a macro to override it :)
#define NSLog(...) CustomLogger(__VA_ARGS__);
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