Discussions

Web tier: servlets, JSP, Web frameworks: issue with log4j / Tomcat

  1. issue with log4j / Tomcat (1 messages)

    Hello,

    Again a newbie encountering problems with log4j...

    I would like to log my webapp, without logging all Tomcat's stuff. So I put in my {TOMCAT_HOME}/common/classes/log4j.properties this :

    log4j.rootLogger=ERROR, A1
    log4j.appender.A1=org.apache.log4j.ConsoleAppender
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout
    log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

    In the {MYWEBAPP_HOME}/WEB-INF/classes/log4j.properties, I put this :
    log4j.rootLogger=DEBUG, A1, logfile
    log4j.appender.A1=org.apache.log4j.ConsoleAppender
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout
    log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
    log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
    log4j.appender.logfile.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
    log4j.appender.logfile=org.apache.log4j.RollingFileAppender
    log4j.appender.logfile.File=c:/logs/mywebapp.log
    log4j.appender.logfile.MaxFileSize=512KB

    I expected to have Tomcat running log4j in error level, and my webapp in debug level(so the console would only show my "logger.debug()" outputs), but instead, Tomcat seems to take the log4j configuration from my webapp, and generates billions of lines per second !!!!

    Please, can someone help me ?
    Thanks

    Hugo
  2. issue with log4j / Tomcat[ Go to top ]

    Hello,Again a newbie encountering problems with log4j...I would like to log my webapp, without logging all Tomcat's stuff. So I put in my {TOMCAT_HOME}/common/classes/log4j.properties this :log4j.rootLogger=ERROR, A1log4j.appender.A1=org.apache.log4j.ConsoleAppenderlog4j.appender.A1.layout=org.apache.log4j.PatternLayoutlog4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%nIn the {MYWEBAPP_HOME}/WEB-INF/classes/log4j.properties, I put this :log4j.rootLogger=DEBUG, A1, logfilelog4j.appender.A1=org.apache.log4j.ConsoleAppenderlog4j.appender.A1.layout=org.apache.log4j.PatternLayoutlog4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%nlog4j.appender.logfile.layout=org.apache.log4j.PatternLayoutlog4j.appender.logfile.layout.ConversionPattern=%d [%t] %-5p %c - %m%nlog4j.appender.logfile=org.apache.log4j.RollingFileAppenderlog4j.appender.logfile.File=c:/logs/mywebapp.loglog4j.appender.logfile.MaxFileSize=512KBI expected to have Tomcat running log4j in error level, and my webapp in debug level(so the console would only show my "logger.debug()" outputs), but instead, Tomcat seems to take the log4j configuration from my webapp, and generates billions of lines per second !!!!Please, can someone help me ?ThanksHugo

    Hi there,
    What the 2 config properties file have are overriding the rootLogger element. Tomcat will load its settings first at which time the rootLogger would be ERROR but once your application log4j.properties are loaded to memory the root logger is set to DEBUG. and this leads to your application generated Debug statements. what u need to do is have 2 configuration files, one solely for tomcat and another for your application? But normally what you wud do is to have 2 appenders and use the appenders to abide by ERROR or DEBUG depending on the environments on to which you are deploying the application. However, if you go thru the log4j documentation you should get a better idea. I have answered this off the top of my hat with minimal reference to the log4j api. so u might wanna consult the api and documentation. and use it to your particular situation!
    Happy New Year
    Nidhin.