I could use some help with my log4j2 configuration. When I debug the logger, it looks like it shuts down all of the appenders, and then I never receive any application logs. Luckily I know that log4j is at least finding the properties file and giving logger initialization debug output.
Here is my log4j2.properties file:
status = debug
name = PropertiesConfig
filters = threshold
filter.threshold.type = ThresholdFilter
filter.threshold.level = info
appenders = console
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yy-MM-dd HH:mm:ss:SSS} %-5p %c{1}:%L - %m%n
rootLogger.level = debug
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
appender.file.type = File
appender.file.name = application
appender.file.fileName=${filename}/propertieslogs.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
Here is the logger debug init output:
DEBUG Starting LoggerContext[name=ROOT] from configuration at null
DEBUG Starting LoggerContext[name=ROOT, org.apache.logging.log4j.core.LoggerContext@448dc39b] with configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration@70ffa0b4...
DEBUG Shutdown hook enabled. Registering a new one.
DEBUG Apache Log4j Core 2.11.1 initializing configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration@70ffa0b4
DEBUG Installed 1 script engine
DEBUG Oracle Nashorn version: 1.8.0_162, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
DEBUG PluginManager 'Core' found 118 plugins
DEBUG PluginManager 'Level' found 0 plugins
DEBUG PluginManager 'Lookup' found 14 plugins
DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
DEBUG PluginManager 'TypeConverter' found 26 plugins
DEBUG createAppenderRef(ref="STDOUT", level="null", Filter=null)
DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
DEBUG createLogger(additivity="null", level="DEBUG", includeLocation="null", ={STDOUT}, ={}, Configuration(PropertiesConfig), Filter=null)
DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
DEBUG createLoggers(={root})
DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
DEBUG PatternLayout$Builder(pattern="%d{yy-MM-dd HH:mm:ss:SSS} %-5p %c{1}:%L - %m%n", PatternSelector=null, Configuration(PropertiesConfig), Replace=null, charset="null", alwaysWriteExceptions="null", disableAnsi="null", noConsoleNoAnsi="null", header="null", footer="null")
DEBUG PluginManager 'Converter' found 44 plugins
DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender].
DEBUG ConsoleAppender$Builder(target="null", follow="null", direct="null", bufferedIo="null", bufferSize="null", immediateFlush="null", ignoreExceptions="null", PatternLayout(%d{yy-MM-dd HH:mm:ss:SSS} %-5p %c{1}:%L - %m%n), name="STDOUT", Configuration(PropertiesConfig), Filter=null)
DEBUG Starting OutputStreamManager SYSTEM_OUT.false.false
DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
DEBUG createAppenders(={STDOUT})
DEBUG Building Plugin[name=filter, class=org.apache.logging.log4j.core.filter.ThresholdFilter].
DEBUG createFilter(level="INFO", onMatch="null", onMismatch="null")
DEBUG Configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration@70ffa0b4 initialized
DEBUG Starting configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration@70ffa0b4
DEBUG Started configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration@70ffa0b4 OK.
DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false.false-1
DEBUG Shut down OutputStreamManager SYSTEM_OUT.false.false-1, all resources released: true
DEBUG Appender DefaultConsole-1 stopped with status true
DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@605d8cc OK
DEBUG Registering MBean org.apache.logging.log4j2:type=ROOT
DEBUG Registering MBean org.apache.logging.log4j2:type=ROOT,component=StatusLogger
DEBUG Registering MBean org.apache.logging.log4j2:type=ROOT,component=ContextSelector
DEBUG Registering MBean org.apache.logging.log4j2:type=ROOT,component=Loggers,name=
DEBUG Registering MBean org.apache.logging.log4j2:type=ROOT,component=Appenders,name=STDOUT
DEBUG org.apache.logging.log4j.core.util.SystemClock does not support precise timestamps.
DEBUG LoggerContext[name=ROOT, org.apache.logging.log4j.core.LoggerContext@448dc39b] started OK with configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration@70ffa0b4.
DEBUG Log4jServletContextListener ensuring that Log4j starts up properly.
DEBUG Log4jServletContextListener ensuring that Log4j shuts down properly.
DEBUG Removing LoggerContext for [ROOT].
DEBUG Stopping LoggerContext[name=ROOT, org.apache.logging.log4j.core.LoggerContext@448dc39b]...
DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false.false
DEBUG Shut down OutputStreamManager SYSTEM_OUT.false.false, all resources released: true
DEBUG Appender STDOUT stopped with status true
DEBUG Stopped org.apache.logging.log4j.core.config.properties.PropertiesConfiguration@70ffa0b4 OK
DEBUG Stopped LoggerContext[name=ROOT, org.apache.logging.log4j.core.LoggerContext@448dc39b] with status true
Thanks for any help! I need it.
I'd really like to get the async appenders working at some point, but its hard to find examples via the log4j2.properties syntax for log4j2
P.S. - here is my pom.xml:
<!-- log4j is used for logging within the application -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.11.1</version>
<scope>runtime</scope>
</dependency>
<!-- slf4j is used to tie Spring to log4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.25</version>
</dependency>