1
votes
# Root logger option
log4j.rootLogger=ALL, stdout, A1
log4j.logger.org.apache.jsp=ALL, stdout, A1

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] [%c:%L] - %m%n

# LOG4J daily rolling log files configuration
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=logs/file.log
log4j.appender.A1.DatePattern='.'yyyy-MM-dd
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] [%c:%L] - %m%n

Most of the time I define several appenders... one for Console and some others into files. But most of the time I used the same layout for the output. Is there a way to define a default one ?

Something like that ?

log4j.appender.layout=org.apache.log4j.PatternLayout
log4j.appender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] [%c:%L] - %m%n
1
@SrikanthLingala It helps ! Thanks...Manu

1 Answers

1
votes
# Root logger option
log4j.rootLogger=ALL, stdout, A1
log4j.logger.org.apache.jsp=ALL, stdout, A1

PATTERN=%d{yyyy-MM-dd HH:mm:ss} [%p] %l - %m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=${PATTERN}

# LOG4J daily rolling log files configuration
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=logs/file.log
log4j.appender.A1.DatePattern='.'yyyy-MM-dd
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=${PATTERN}

It seems that the only way to do this is to set a variable, as I've done with PATTERN=%d{yyyy-MM-dd HH:mm:ss} [%p] %l - %m%n