You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Er...@bcbsks.com on 2007/04/03 20:38:55 UTC
log4j - Level creation in config file
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
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: log4j - Level creation in config file
Posted by Er...@bcbsks.com.
Thanks again Curt!
As I have milled over in my mind your ideas and my needs, I came to your
solution. I don't have to have the Formatter output AUDIT: by using the
%Priority, I can make the log record look any way I want for this group
of log records just like you stated below and all without me writing more
Java code.
Eric
On Apr 3, 2007, at 4:14 PM, Eric.Wolf@bcbsks.com wrote:
>
> 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?
>
> Thanks,
> Eric
>
If you set the threshold on the root logger to ERROR and the
threshold on "audit" to INFO, then you should get all INFO level and
higher messages logged to any logger that starts with "audit." and
ERROR and higher level messages on any other logger. I think that
would do what you want and be much simpler than trying to introduce a
custom level.
> I want to treat the "Audit" level as data for auditors
That clearly suggests that the audience is different, not that the
message has a higher or lower significance than one of the existing
levels. Consider that "auditors" may assign different significance
to different messages, so you might want to do something like:
auditLogger.info("Expense statement 10104 accepted and reimbursement
for $10.71 issued");
auditLogger.error("CEO has transferred $10.57 million dollars into
personal bank account");
> My plan was
> to extend or something a new "Audit" level and set it to an integer of
> 45,000.
Others who have had similar ideas placed Audit down somewhere between
DEBUG and INFO. The difference in opinion on the correct value
suggests that is really is orthogonal to significance.
Use a different branch of the logger hierarchy, you will be much
happier.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: log4j - Level creation in config file
Posted by Curt Arnold <ca...@apache.org>.
On Apr 3, 2007, at 4:14 PM, Eric.Wolf@bcbsks.com wrote:
>
> 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?
>
> Thanks,
> Eric
>
If you set the threshold on the root logger to ERROR and the
threshold on "audit" to INFO, then you should get all INFO level and
higher messages logged to any logger that starts with "audit." and
ERROR and higher level messages on any other logger. I think that
would do what you want and be much simpler than trying to introduce a
custom level.
> I want to treat the "Audit" level as data for auditors
That clearly suggests that the audience is different, not that the
message has a higher or lower significance than one of the existing
levels. Consider that "auditors" may assign different significances
to different messages, so you might want to do something like:
auditLogger.info("Expense statement 10104 accepted and reimbursement
for $10.71 issued");
auditLogger.error("CEO has transferred $10.57 million dollars into
personal bank account");
> My plan was
> to extend or something a new "Audit" level and set it to an integer of
> 45,000.
Others who have had similar ideas placed Audit down somewhere between
DEBUG and INFO. The difference in opinion on the correct value
suggests that is really is orthogonal to significance.
Use a different branch of the logger hierarchy, you will be much
happier.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: log4j - Level creation in config file
Posted by Er...@bcbsks.com.
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?
Thanks,
Eric
Curt Arnold
<carnold@apache.o
rg> To
Log4J Users List
04/03/2007 03:32 <lo...@logging.apache.org>
PM cc
Topic
Please respond to
"Log4J Users Subject
List" Re: log4j - Level creation in
<log4j-user@loggi config file
ng.apache.org>
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
concerns
private static final Logger auditLogger = Logger.getLogger
("audit.revenue");
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
Re: log4j - Level creation in config file
Posted by Curt Arnold <ca...@apache.org>.
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
concerns
private static final Logger auditLogger = Logger.getLogger
("audit.revenue");
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