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 Bi...@certegy.com on 2002/09/13 18:34:36 UTC

How to add or activate an appender from within a program

I am working with an application which may or may not have access to the
console / stdout / stderr.

The configuration file looks like this:

- - - -

# AS400 Java pgmd do not have console unless running in QSHELL
#log4j.rootLogger=DEBUG, A1, A2, A3
log4j.rootLogger=DEBUG, A1, A3

#log4j.debug=false -- suppress start up log4j messages
log4j.debug=false
log4j.info=true
log4j.warn=true
log4j.error=true
log4j.fatal=true


# A1 is set to be a RollingFileAppender for debugging noise.
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=${user.debugLog}
log4j.appender.A1.MaxFileSize=500KB
# Keep one backup file
log4j.appender.A1.MaxBackupIndex=1
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} %-5p [%t]: %c{3} -
%m%n


# AS400 Java pgmd do not have console unless running in QSHELL
# A2 is set to be a ConsoleAppender for INFO and up.
log4j.appender.A2=org.apache.log4j.ConsoleAppender
log4j.appender.A2.threshold=INFO
# A2 uses PatternLayout.
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-5p [%t]: %c{3} - %m%n



# A3 is set to be a RollingFileAppender for serious errors (ERROR and
FATAL).
log4j.appender.A3=org.apache.log4j.RollingFileAppender
log4j.appender.A3.threshold=ERROR
log4j.appender.A3.File=${user.errorLog}
log4j.appender.A3.MaxFileSize=100KB
# Keep one backup file
log4j.appender.A3.MaxBackupIndex=1
# A3 uses PatternLayout.
log4j.appender.A3.layout=org.apache.log4j.PatternLayout
log4j.appender.A3.layout.ConversionPattern=%d{ISO8601} %-5p [%t]: (%F:%L) -
%m%n



#log4j.debug=true - have to turn on in application if wish to suppress
start up logging

- - - -

Appender A1 logs everything to a debug log
Appender A3 logs ERROR and FATAL to an error log

The program can detect whether the console is available.  If the program
has access to the console | stdout | stderr I want to make appender A2
active|attached so the messages can be seen.  If the program does not have
access to the console I'll leave A2 unattached.

I tried

      static Logger lg = Logger.getLogger("utility.cvtToHfs.PadRecord");
.
.
      Appender A2 = lg.getAppender("A2");
      lg.addAppender(A2);

But that had no effect.  I can't figure out how to tell A2 to log DEBUG and
up messages.

Can anyone help me out with some suggestion on how to do this?  Code
example will be helpful because I am still learning.

Thanks all
Bill Blalock





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>