I want to change the default logging from tocat to use log4j2 instead of java logging
I needed these 3 libs to simple log into catalia.out
- log4j-api-2.11.1.jar
- log4j-core-2.11.1.jar
- log4j-jul-2.11.1.jar
create a log4j2.xml
under $CATALINA_HOME/conf/
<Configuration status="warn" name="catalina" packages="">
<Appenders>
<RollingFile name="catalina" fileName="${sys:catalina.base}/logs/catalina.out"
filePattern="${sys:catalina.base}/logs/catalina.%d{yyyy-MM-dd}.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
</Policies>
</RollingFile>
<Async name="Async">
<AppenderRef ref="catalina"/>
</Async>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Async"/>
<!-- <AppenderRef ref="catalina"/> -->
</Root>
</Loggers>
</Configuration>
setenv.sh
script are automatic executed during catalina.sh execution. it helps to keep customization seperate.
create the file under $CATALINA_HOME/bin/
#!/bin/sh
CLASSPATH=$CLASSPATH:$CATALINA_HOME/bin/log4j-jul-2.11.1.jar:$CATALINA_HOME/bin/log4j-api-2.11.1.jar:$CATALINA_HOME/bin/log4j-core-2.11.1.jar
LOGGING_CONFIG="-Dlog4j.configurationFile=file://$CATALINA_HOME/conf/log4j2.xml"
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager"
LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
CATALINA_OUT=/dev/null
todo