Log4j config problem

Discussion in 'Java' started by Dariusz Szczesniak, Jul 12, 2005.

  1. 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();
    }
    }
    Dariusz Szczesniak, Jul 12, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandra Stehman

    eclipse, junit, log4j, & finding log4j.xml

    Alexandra Stehman, Jan 19, 2004, in forum: Java
    Replies:
    0
    Views:
    5,757
    Alexandra Stehman
    Jan 19, 2004
  2. Alex Hunsley
    Replies:
    2
    Views:
    12,914
    =?ISO-8859-15?Q?Fr=E9d=E9ric_G=E9din?=
    May 28, 2004
  3. Rodolfo
    Replies:
    0
    Views:
    946
    Rodolfo
    Jul 12, 2004
  4. joes
    Replies:
    1
    Views:
    2,120
  5. Gianni Galore
    Replies:
    0
    Views:
    1,257
    Gianni Galore
    Sep 8, 2010
Loading...

Share This Page