You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2003/10/09 00:29:13 UTC
DO NOT REPLY [Bug 23688] New: -
Provide a method to get the ant logging level for the log4j appender
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23688>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23688
Provide a method to get the ant logging level for the log4j appender
Summary: Provide a method to get the ant logging level for the
log4j appender
Product: Ant
Version: 1.5.1
Platform: All
OS/Version: All
Status: NEW
Severity: Enhancement
Priority: Other
Component: Optional Tasks
AssignedTo: dev@ant.apache.org
ReportedBy: mkerr@webct.com
I am using the the code that follows to set up an appender to ant log file from
the log4j events. The only problem is I cannot set the log4j logging level
according to the ant logging level because there is no method to get the ant
logging level. In order to see the logging then I must set logging in log4j to
all and then let ant logging filter but this can really hurt performance if
there is alot of logging.
// redirect log4j to ant logger
Appender appender = Log4jToAnt.getAppenderForTask( this);
Logger rootLogger = LogManager.getRootLogger();
Level savedRootLoggerLevel = rootLogger.getLevel();
if( log4jDebug ) {
rootLogger.setLevel( Level.ALL); // turn on all logging and let ant filter
} else {
rootLogger.setLevel( Level.ERROR); // turn off logging for improved speed
}
// TODO: performance improvement: find out way to detect ant logging level and
set appropriately.
// Note: Ant does not expose the logging value so we would need to modify ant
!!! arg
BasicConfigurator.configure( appender);
public static final int getAntMsgInt( Level level ) {
if( level == Level.DEBUG ) {
return Project.MSG_DEBUG;
} else if( level == Level.INFO ) {
return Project.MSG_VERBOSE;
} else if( level == Level.WARN ) {
return Project.MSG_WARN;
} else if( level == Level.ERROR ) {
return Project.MSG_ERR;
} else if( level == Level.FATAL ) {
return Project.MSG_ERR;
} else {
return Project.MSG_VERBOSE;
}
}
public static final Appender getAppenderForTask( final Task task) {
return new AppenderSkeleton() {
Task _task = task;
{
_task.log( "Started redirect of log4j to ant logger", Project.MSG_VERBOSE );
}
public void append(LoggingEvent event) {
_task.log( event.getLoggerName().substring(
event.getLoggerName().lastIndexOf( ".")+1) + " " + event.getRenderedMessage(),
getAntMsgInt( event.getLevel()));
}
public void close() {
}
public boolean requiresLayout() {
return false;
}
};
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org