logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric.W...@bcbsks.com
Subject Re: log4j - Level creation in config file
Date Tue, 03 Apr 2007 21:14:14 GMT

Thanks Curt!  I like your thoughts.

Here are some more details to clarify.

I want to treat the "Audit" level as data for auditors and I want it to log
when it is in production and the RootLogger is set to "ERROR".  My plan was
to extend or something a new "Audit" level and set it to an integer of
45,000.  This way it will be logged in production and when the formatter
outputs the "Priority", I will get on the log record "AUDIT".  That is my
goal and I thought that warranted a new level.  If I use anything below
"ERROR" as the level, it won't log in production.  I guess I could set the
"threshold" on that set of loggers lower so I could use like "INFO" but I
will get all the others I don't want as well.

Does my need warrant a new level?  Any other thoughts?


             Curt Arnold                                                   
             rg>                                                        To 
                                       Log4J Users List                    
             04/03/2007 03:32          <log4j-user@logging.apache.org>     
             PM                                                         cc 
             Please respond to                                             
               "Log4J Users                                        Subject 
                   List"               Re: log4j - Level creation in       
             <log4j-user@loggi         config file                         

On Apr 3, 2007, at 1:38 PM, Eric.Wolf@bcbsks.com wrote:

> Can you create new Level(s) in the configuration file (for example:
> log4j.level.Audit = "something here"?
> Or should I just extend the Level class?
> Thanks,
> Eric Wolf

log4j doesn't support on-the-fly level creation in configuration
files.  There had been some thought of allowing a numeric level value
to be used, but no code has ever been placed around that.

I would strongly encourage you to think through your use cases (and
perhaps describe them here).  Many times when custom levels are
considered, the goal is actually to characterize the intended
audience or destination of the message, both of which are better
accomplished using the logger name than the level.   Level is a
continuum of significance with certain values being assigned symbolic
names (trace, debug, info, warn, error, fatal).   Does "audit" fit in
there somewhere?

Likely it closer to a "topic" or "subject" that is better served use
of the logger name?  Many people get misled into thinking that logger
names have to be class names since it is a common use pattern (where
it basically means a topic regarding the implementation of the class
of the same name), but it is not limited to that.  I'd suggest
thinking about having two distinct logger instances in your class,
one named after the class to capture implementation diagnostics
intended for diagnosticians and a separate one for messages intended
for auditors.

public class Foo {
      private static final Logger logger = Logger.getLogger(Foo.class);
      //   you can play with logger name patterns to address your
      private static final Logger auditLogger = Logger.getLogger

This discussion has been gone over quite a few times, you might
search the archives for the following terms "audience", "audit",
"diagnostician", "custom level".

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message