Perhaps this is a situation that would warrant creating a new logging
level:
There are some messages that we want to always appear in our logs,
but we don't want to identify them as FATAL errors.
These messages indicate the beginning and ending of certain important
processes.
To facilitate this requirement, we:
1. Created a Log4JHelper Class that does things like setting up our
ConfigureAndWatch
2. Created a MyLevel class in the Helper class as:
private static class MyLevel extends Level {
private MyLevel(int level, String name, int sysLogLevel) {
super(level, name, sysLogLevel);
}
}
3. Created a STATUS Level in the Helper Class as:
/**
* Provides a Log4J [EMAIL PROTECTED] org.apache.log4j.Level Level} that
always logs unless logging is completely turned off.
*/
public static final Level STATUS_LEVEL = new MyLevel
(Priority.FATAL_INT + 10, "STATUS", SyslogAppender.LOG_LOCAL0);
Now, when we want to log something at the STATUS level, we use the
following Logger instantiation, and log call:
private static final Logger LOG = Logger.getLogger
(SomeClass.class);
.
.
.
LOG.log(Log4JHelper.STATUS_LEVEL,"Some Message");
On Dec 21, 2005, at 12:33 AM, Curt Arnold wrote:
On Dec 20, 2005, at 5:45 AM, Joseph, Shinoy wrote:
Hi,
I am in need of adding a new level logging in to the log4j.
Requirement is that the new level should be independent of the
existing levels(debug,warn,info error,fatal etc).
I have added the new level by extending Level, Logger and
LoggingFactory classes.
Is it possible to do that by customizing log4j.xml ? It will be
great if some could guide me in this regard.
Thanks & Regards
Shinoy
As you've noticed, it isn't easy to do and it makes you maintain a
branched version of log4j.
In many cases, people add levels for reasons that are much better
addressed by using the logger hierarchy more effectively. For
example, they'd like to add a level SECURITY or AUDIT when that is
more a description of the intended audience instead of the
significance of the message to the audience. In that case, having
a branch of the logger hierarchy for security related messages
("security.myapp.foo") is better than logging a message of
Level.SECURITY to "myapp.foo".
If you explain your requirements, maybe we can find a decent
solution that doesn't require you maintaining your own branched
copy of log4j.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]