[newbie] How to have different logging levels for different classes ?

196 views
Skip to first unread message

Colas

unread,
Apr 16, 2013, 12:39:07 PM4/16/13
to cocoalu...@googlegroups.com
Hi,

I am learning programming and all the const/extern/static stuff is quite unclear for me.
Please excuse my silliness :)

I am using the four different DDLog.
I declare the log level in the Prefix.pch with

static int ddLogLevel = LOG_LEVEL_WARN;


But, I would like to have a different level for a given class (call it MyClass)
For instance, my "global level" is WARN but for a given class, I would like to have VERBOSE.
I read the wiki page on this topic (https://github.com/robbiehanson/CocoaLumberjack/wiki/DynamicLogLevels) but it seems to be different from what I want.

I would to add a definition outside of the @implementation of MyClass, something like : 

ddLogLevel = LOG_LEVEL_VERBOSE;


The compiler does not let me do that (Redefinition of ddLogLevel).


Do you see what I would like to do ?

Is it possible ?

Or maybe, due to my misunderstanding of global variable, impossible ?



Thank you

Colas

Robbie Hanson

unread,
Apr 16, 2013, 3:03:15 PM4/16/13
to cocoalu...@googlegroups.com
Hi Colas,

Think of 'static' as meaning "pertaining to this file only".

So for example, if your MyClass.m file starts with this:

static int ddLogLevel = LOG_LEVEL_WARN;

Then the 'ddLogLevel' ivar is scoped to that file only.

For instance, my "global level" is WARN but for a given class, I would like to have VERBOSE.

The compiler does not let me do that (Redefinition of ddLogLevel).

Most of the examples demonstrate always declaring the log level on a per-file only. That is, there is no global definition of ddLogLevel anywhere. It is always declared at the top of each *.m file. You are asking about using a combination of both global and local (static, per-file).

One way to accomplish this is to define your global log level using something like this:

#define DEFAULT_LOG_LEVEL   LOG_LEVEL_WARN;

And then, at the top of each *.m file:

static int ddLogLevel = DEFAULT_LOG_LEVEL;

That way, you still have a global log level that can be changed in a single location. However, you also have the option of overriding it on a per-file basis.

-Robbie Hanson

--
You received this message because you are subscribed to the Google Groups "CocoaLumberjack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocoalumberja...@googlegroups.com.
To post to this group, send email to cocoalu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/cocoalumberjack/-/KV2wSr2LbjsJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages