1

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;
#else
static const int ddLogLevel = LOG_LEVEL_ERROR;
#endif

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

rmaddy
  • 314,917
  • 42
  • 532
  • 579
hasan
  • 23,815
  • 10
  • 63
  • 101
  • I fully understood the two answers below. but, I dont see a single line of code where ddLogLevel is used. how this is working guys? maybe I am missing that line! – hasan Nov 11 '16 at 21:35
  • 1
    Just add that code to the top of your AppDelegate.m. Or setup different log levels as needed. The CocoaLumberjack documentation talks about how to setup different log levels. – rmaddy Nov 11 '16 at 21:43
  • I am using lumberjack for while now. but I only use DDLogVerbose. and I log those into a file and let my testers send it to me by email. by pressing a button on the app I set only for testflight users. I wonna use lumberjack with crashlytics. so I needed to understand a few things to get advantage of both tools. ty you all for help. – hasan Nov 11 '16 at 21:48
  • Only using `DDLogVerbose` is a bad practice. Use the proper `DDLogXXX` method. Then you can get just the desired messages when/if needed. – rmaddy Nov 11 '16 at 21:50

2 Answers2

2

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • I posted the following question. can you help please. http://stackoverflow.com/questions/40568997/global-import-for-swift-cocoalumberjack – hasan Nov 12 '16 at 23:48
2

Those are varying degrees of logging granularity. LOG_LEVEL_ALL means any and every log will be written to the console and file that lumberjack uses. LOG_LEVEL_OFF is the other end of the extreme where no logging happens. You can use these to determine what kind of logs to show for which build. Here are some examples of use cases.

- (void)viewDidLoad
{
    [super viewDidLoad];

    // this log isn't particularly useful for a production build, 
    // but can be helpful when debugging. So we use verbose.
    DDLogVerbose(@"This view controller loaded");
}

- (void)didRecieveMemoryWarning
{
    // This is a bad situation, but it isn't an error really.
    // Just a signal that we need to free up memory. So we use warning.
    DDLogWarning(@"We are using too much memory.");
}

- (void)doSomething
{
    NSError *error;
    [self doSomethingElse:&error];
    if (error) {
        // This is definitely an error we need to handle. If you have to
        // look through crash logs on a production build, you definitely
        // want this log to show up there.
        DDLogError(@"Encountered an error: %@", error);
    }
}

In these examples, all of the logs will show up when you run your app from Xcode, but only the error log will show up in a production crash log. The ddLogLevel constant is how you determine what level of logging you want.

keithbhunter
  • 12,258
  • 4
  • 33
  • 58
  • I posted the following question. can you help please. http://stackoverflow.com/questions/40568997/global-import-for-swift-cocoalumberjack – hasan Nov 12 '16 at 23:49