hasan83 hasan83 - 11 months ago 68
Objective-C Question

CocoaLumberjack log level

I don't really understand what log level means.

In Lumbejack the following log levels defined:

#define LOG_LEVEL_OFF DDLogLevelOff
#define LOG_LEVEL_ERROR DDLogLevelError
#define LOG_LEVEL_WARN DDLogLevelWarning
#define LOG_LEVEL_INFO DDLogLevelInfo
#define LOG_LEVEL_DEBUG DDLogLevelDebug
#define LOG_LEVEL_VERBOSE DDLogLevelVerbose
#define LOG_LEVEL_ALL DDLogLevelAll

What some of those mean? and how they are used?
Is those related to CocoaLumberjack all for iOS?

Also, I use the following code in my pch file:

#ifdef DEBUG
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
static const int ddLogLevel = LOG_LEVEL_ERROR;

What those mean? I searched the project for the
var and I didnt find it used anywhere. also, not in lumberjack pod.

Answer Source

Setting the ddLogLevel filters what messages appear from the various DDLogXXX methods.

If you set ddLogLevel to LOG_LEVEL_ALL then all DDLogXXX methods will be logged. If you set ddLogLevel to LOG_LEVEL_INFO then only Info, Warning, and Error will be logged.

Just look at the list of #define lines you show. Selecting a given value results in only messages from that level and those higher up in the list.

If you set ddLogLevel to LOG_LEVEL_INFO and you have the following two lines:

DDLogInfo("some info message");
DDLogDebug("some debug message");

Then only the first message will be logged because Debug is lower than Info.

The actual meaning of each level is somewhat subjective. Just use them consistently in your app. The most important or critical messages should have the highest levels and the least important should have the lower level.

I use DDLogError when my app encounters unexpected values or when a method that provides an NSError parameter fails. I log a relevant message and include the NSError value.

I use DDLogInfo for "I'm here" type messages.

I use DDLogDebug to log variable values.

I don't use DDLogWarn too often but you could use it for unexpected issues where there isn't an actual error but something important to note.