On Jun 6, 2008, at 11:09 AM, Julius Davies wrote:
Hi, Douglas, Jason,
Jason - thanks for your feedback! I'll definitely incorporate some of
that, especially around what's appropriate for each level.
Douglas - it's not as bad as writing my own layout, but it will make
some people uncomfortable! Here's the trick for changing the level
strings:
The "levelStr" member on Level has default ("package") access, and
it's writable. So in my webapp or jar file I usually create one new
class in the "org.apache.log4j" package that looks like this:
package org.apache.log4j;
public class LevelChanger {
public static void changeLevels() {
Level.DEBUG.levelStr = "_";
Level.INFO.levelStr = " ";
Level.WARN.levelStr = "!";
Level.ERROR.levelStr = "*";
Level.FATAL.levelStr = "***";
}
}
Even though LevelChanger is code I write and package in a separate jar
file, as long as I declare it part of the "org.apache.log4j", it can
change the level strings.
yours,
Julius
log4j leaves a lot of things package access which is a bad practice.
Expect kludge to not work if and when there is a log4j 2.0.
The LevelConverter in the EnhancedPatternLayout (the back port of the
log4j 1.3 PatternLayout) in the extras companion could be extended to
support arbitrary remapping of levels. Basically, the parser now
supports parameters for the conversion characters which is used for
conversion patterns and timezones for %d and little else. I'd suggest
using the parameter and a map between levels and labels.
Potential patterns:
%p{DEBUG=_,INFO= ,WARN=!,ERROR=*,FATAL=***,25000=?}
%p{{DEBUG,_}, {INFO, },{WARN,!},{ERROR,*},{FATAL,***},{25000,?}}
The second has the advantage of resembling the toString() of the Map
that would back the converter, however I don't think the PatternParser
is sophisticated enough to handle the nested braces.
Would you consider moving your content to the log4j Wiki?
You use Logger.getLog() in the example where it should be
Logger.getLogger().
You mention gzipping rolled log files which is supported automatically
by the org.apache.log4j.extras.RFA in the extras companion.
EnhancedPatternLayout allows you to specify an arbitrary timezone in
the second parameter, like %d{}{GMT}.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]