0

I'm having problems getting logging working with my Web App using Maven to build and Jetty as the Web Server. My log4j.proporties file looks like:

#
log4j.rootLogger=debug,file
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=C:/logs/Stats.log
log4j.appender.file.MaxFileSize=2MB
log4j.appender.file.MaxBackupIndex=2
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d %t [%5p][%c{1}] %m%n

#log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
#log4j.appender.CONSOLE.threshold=INFO
#log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
#log4j.appender.CONSOLE.layout.ConversionPattern=%d %t [%5p][%c{1}] %m%n
#log4j.appender.CONSOLE.target=System.err

# RTS file logger
log4j.appender.RTS=org.apache.log4j.RollingFileAppender
log4j.appender.RTS.File=C:/logs/RTS.log
log4j.appender.RTS.MaxBackupIndex=10
log4j.appender.RTS.MaxFileSize=10MB
log4j.appender.RTS.append=true
log4j.appender.RTS.layout=org.apache.log4j.PatternLayout
log4j.appender.RTS.layout.ConversionPattern=%d [%t] %-m%n

# Level tuning
#log4j.logger.org.cometd=INFO
log4j.logger.com.realtime=INFO, RTS

and my Main Class looks like:

import org.apache.log4j.Logger;

public class Main {

    static final Logger logger = Logger.getLogger(Main.class);

    public static void main(String[] args) {
        logger.info("Info Message!");
            ...
            ...
    }
}

Does anyone know why i'm not getting the "Info Message!" to appear in my RTS.log File? The File gets created but is empty when the application is run. My Main Class is currently in the Package com.realtime

user676567
  • 1,119
  • 9
  • 20
  • 39
  • Any joy if you change your opening line to include RTS so it reads...`log4j.rootLogger=DEBUG,file,RTS` – Brad Feb 06 '13 at 16:20
  • Thanks for your response Brad, that's spitting out CometD stuff now to the RTS.log File which is the same output that's in my Stats.log file but i still cant see the Logger Message from the Main Class. – user676567 Feb 06 '13 at 16:58
  • '2013-02-06 16:45:12,962 [main] Logging to org.slf4j.impl.Log4jLoggerAdapter(org.eclipse.jetty.util.log) via org.eclipse.jetty.util.log.Slf4jLog 2013-02-06 16:45:12,962 [main] Cross-origin filter configuration: allowedOrigins = *, allowedMethods = GET,POST,HEAD, allowedHeaders = X-Requested-With,Content-Type,Accept,Origin, preflightMaxAge = 1800, allowCredentials = true 2013-02-06 16:45:19,750 [qtp4265293-16] Cross-origin request to /cometd/connect is a preflight cross-origin request' – user676567 Feb 06 '13 at 16:59

1 Answers1

0

Yeah, tricky one. This post describes how to use the additivity setting to prevent logging the same package to different log files as caused by my suggestion in the comments. So something like this...

log4j.additivity.com.cometd=false
log4j.additivity.com.realtime=false

log4j.logger.com.cometd.file=DEBUG, file
log4j.logger.com.realtime.RTS=DEBUG, RTS
Community
  • 1
  • 1
Brad
  • 15,186
  • 11
  • 60
  • 74