core
core copied to clipboard
Issue 23631 create global log4j
Updated pull request from https://github.com/dotCMS/core/pull/23632 Issue #23631 Enable log configuration by setting environment variable USE_GLOBAL_LOG4J=true
Default logging config found in log4j2/conf/log4j2-tomcat.xml
bin/setclasspath.sh or bin/setclasspath.bat contains logic to setup
if [ "$USE_GLOBAL_LOG4J" = true ]; then echo Using Global Log4j CLASSPATH="$CATALINA_HOME/log4j2/lib/*:$CATALINA_HOME/log4j2/conf$CLASSPATH" JAVA_OPTS=" -DLog4jContextSelector=org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector $JAVA_OPTS" JAVA_OPTS=" -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager $JAVA_OPTS" fi
default Context selector creates a new context per Classloader and requires separate configuration for each. BasicContextSelection keeps the same context and configuration for all Classloaders, for each there is an Async version that makes all the loggers asynchronous and improves performance.
The log4j jars have been added to $CATALINA_HOME/log4j2/lib to support slf4j, commons-logging, Jul logging log4j 1. A log4j2-appserver jar is set up to replace the standard tomcat logging. Although the log4j2-appserver replaces the jul logging in tomcat directly Some plugin code uses java.util.logging and the LogManger needs to be set to pass this logging back to log4j.
By default the logfile is picked up from the classpath and found in CATALINA_HOME/log4j2/conf see
https://logging.apache.org/log4j/2.x/log4j-appserver/index.html
The log file could be specified with a jvm option -Dlog4j.configurationFile=path/to/log4j2.xml or map the file/folder in docker.
Read configuration guide https://logging.apache.org/log4j/2.x/manual/configuration.html on how to modify the config,https://logging.apache.org/log4j/2.x/manual/configuration.html It is currently set to only log to stdout. for docker.