logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dariusz <dariu...@nyc.rr.com>
Subject Log4j config problem
Date Thu, 14 Jul 2005 16:28:24 GMT
Hi,

    I am migrating an application from JDK logger to Log4j 1.2.9 (using
Tomcat 5.0.28) and almost got it to work, except for one remaining
issue.  Hopefully someone will be able to give me some tips on how to
solve it.
What I want to have is a separate log file for all Tomcat output
(log4j.log containing info about starting/stopping service,
initializing, etc.) and two separate log files for the application
output: an Error.log file which will let me quickly see any errors that
might have occurred, and another file, All.log containing all debug
info.
    Both Error.log and All.log are OK.  The problem is with 'log4j.log'
file.  While it correctly shows all relevant Tomcat log messages, it
also includes all application debug messages (duplicating All.log
file).  Because of all the included debug messages it is very difficult
to spot any Tomcat errors that might have occurred.  I can suppress the
debug messages in log4j.log by disabling the appender for All.log, but I
would like to keep All.log and have log4j.log only display server info.
Any help would be greatly appreciated.

Thanks.
--Dariusz.


Here is my log4j.properties file:

log4j.rootLogger=ERROR, R
log4j.disable=INFO

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.DatePattern='.'yyyy-MM-dd
log4j.appender.R.File=../logs/log4j.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.logger.org.apache=INFO


AppLog.properties

#
log4j.logger.AppLogger = ALL, DebugAppender, ErrorAppender
log4j.appender.DebugAppender = org.apache.log4j.RollingFileAppender
log4j.appender.DebugAppender.MaxFileSize = 1000KB
log4j.appender.DebugAppender.MaxBackupIndex = 1000
log4j.appender.DebugAppender.Append = true
log4j.appender.DebugAppender.Threshold = DEBUG
log4j.appender.DebugAppender.File = ../webapps/mdinfo/logs/All.log
log4j.appender.DebugAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.DebugAppender.layout.ConversionPattern=%d{MM/dd/yy
HH:mm}%m\n
#
log4j.appender.ErrorAppender = org.apache.log4j.RollingFileAppender
log4j.appender.ErrorAppender.MaxFileSize = 1000KB
log4j.appender.ErrorAppender.MaxBackupIndex = 1000
log4j.appender.ErrorAppender.Append = true
log4j.appender.ErrorAppender.Threshold = ERROR
log4j.appender.ErrorAppender.File = ../webapps/mdinfo/logs/Errors.log
log4j.appender.ErrorAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.ErrorAppender.layout.ConversionPattern=%d{MM/dd/yy
HH:mm}%p %m\n


I also have a Logger.java class, which reads the 'AppLog.properties'
file and gets an org.apache.log4j.Logger.  This logger is then used to
call various log() methods.  Param 'fileName' is set to
AppLog.properties (see above).

 // ---------------------------------------------------
 private synchronized void createJavaLogger(String fileName)
 {
  Properties props = new Properties();

  try
  {
   ClassLoader myLoader = Logger.class.getClassLoader();
   URL propertiesFileURL = myLoader.getResource(fileName);
   FileInputStream fis = new
FileInputStream(propertiesFileURL.getFile());
   props.load(fis);

   PropertyConfigurator.configure(props);
   javaLogger1 = org.apache.log4j.Logger.getLogger("AppLogger");

  }catch (Exception e) {
   System.out.println("Error setting-up Logger and/or handlers." +
e.getMessage());
   e.printStackTrace();
   javaLogger1 = org.apache.log4j.Logger.getRootLogger();
  }
 }

Thanks again.





---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message