Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Log level per logger #86

Closed
erlichmen opened this Issue · 1 comment

2 participants

@erlichmen

Is there a way to set the log level per logger? according to the documentation on the main page there should be a way. I couldn't find any reference for that in the code.
I want the console logger to be in verbose while the file in warn level.

Other than write a specific method in the logger class to do that, is there another way?

@robbiehanson

You can set the filter for each individual logger. And since "a formatter, is a filter, is a formatter" (as I like to say), this actually means:

[logger setLogFormatter:myLoggerFilter];

Your custom filter could be something as simple as this (although you can certainly get fancier with it if you want):

@interface MyLoggerFilter : NSObject <DDLogFormatter>
{
}

@end

@implementation MyLoggerFilter

- (NSString *)formatLogMessage:(DDLogMessage *)logMessage
{
    if (logMessage->logLevel > LOG_LEVEL_WARN)
    {
        // We can filter this message by simply returning nil
        return nil;
    }
    else
    {
        // We could format this message if we wanted to here.
        // But this example is just about filtering.
        return logMessage->logMsg;
    }
}

@end

For more information see https://github.com/robbiehanson/CocoaLumberjack/wiki/CustomFormatters

The above example was lifted from the ContextFilter example in the repository (Xcode/ContextFilter).

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.