I'm completely new to springboot and log4j2, and I cannot manage to send e-mail for a certain type of log (Warn&Error). I dont' understand why i get "ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.SmtpAppender" message. Does anyone have a clue?
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configuration SYSTEM "log4j2.dtd">
<Configuration status="debug" monitorInterval="30">
<Appenders>
<SMTP name="Mailer" subject="Error Log" to="email#email.com"
from="email2#email.com"
smtpHost="host" smtpUsername="username"
smtpPassword="mdp" smtpProtocol="smtp"
bufferSize="50">
<HtmlLayout />
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %c:%L - %m%n" />
</SMTP>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Mailer" />
</Root>
</Loggers>
</Configuration>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>smtp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>smtp</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
SmtpApplication.java
package com.example.smtp;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SmtpApplication {
private static final Logger logger = LogManager.getLogger(SmtpApplication.class);
public static void main(String[] args) {
SpringApplication.run(SmtpApplication.class, args);
logger.debug("Debugging log");
logger.info("Info log");
logger.warn("Hey, This is a warning!");
logger.error("Oops! We have an Error. OK");
logger.fatal("Damn! Fatal error. Please fix me.");
}
}
LOG
2023-01-24 17:30:17,730 main DEBUG AsyncLogger.ThreadNameStrategy=UNCACHED (user specified null, default is UNCACHED)
2023-01-24 17:30:17,731 main DEBUG org.apache.logging.log4j.core.util.SystemClock supports precise timestamps.
2023-01-24 17:31:47,540 Log4j2-TF-4-Scheduled-2 INFO Source 'C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml' was modified on Tue Jan 24 17:31:33 CET 2023 (1674577893351), previous modification was on Tue Jan 24 17:29:57 CET 2023 (1674577797490)
2023-01-24 17:31:47,542 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Reconfiguration started for context 6d5380c2 (org.apache.logging.log4j.core.LoggerContext#7674b62c)
2023-01-24 17:31:47,544 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG PluginManager 'Lookup' found 17 plugins
2023-01-24 17:31:47,546 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Closing FileInputStream java.io.FileInputStream#465ecc51
2023-01-24 17:31:47,550 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Watching configuration 'C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml' for lastModified Tue Jan 24 17:31:33 CET 2023 (1674577893351)
2023-01-24 17:31:47,552 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Apache Log4j Core 2.19.0 initializing configuration XmlConfiguration[location=C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml]
2023-01-24 17:31:47,553 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG PluginManager 'Core' found 131 plugins
2023-01-24 17:31:47,554 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG PluginManager 'Level' found 0 plugins
2023-01-24 17:31:47,554 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG PluginManager 'Lookup' found 17 plugins
2023-01-24 17:31:47,556 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.HtmlLayout].
2023-01-24 17:31:47,557 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG HtmlLayout$Builder(locationInfo="null", title="null", contentType="null", charset="null", fontSize="null", fontName="null", datePattern="null", timezone="null")
2023-01-24 17:31:47,557 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
2023-01-24 17:31:47,558 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG PatternLayout$Builder(pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %c:%L - %m%n", PatternSelector=null, Configuration(C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", disableAnsi="null", noConsoleNoAnsi="null", header="null", footer="null")
2023-01-24 17:31:47,558 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG PluginManager 'Converter' found 48 plugins
2023-01-24 17:31:47,559 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.SmtpAppender].
2023-01-24 17:31:47,561 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG SmtpAppender$Builder(to="email#email.com", cc="null", bcc="null", from="email2#email.com", replyTo="null", subject="Error Log", smtpProtocol="smtp", smtpHost="host", smtpPort="null", smtpUsername="username", smtpPassword="*****", smtpDebug="null", bufferSize="50", SSL=null, ignoreExceptions="null", HtmlLayout(org.apache.logging.log4j.core.layout.HtmlLayout#42614042), name="Mailer", Configuration(C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml), Filter=null, ={})
2023-01-24 17:31:47,563 Log4j2-TF-3-ConfigurationFileWatcher-3 ERROR appender SMTP has no parameter that matches element PatternLayout
2023-01-24 17:31:47,566 Log4j2-TF-3-ConfigurationFileWatcher-3 ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.SmtpAppender for element SMTP: java.lang.NoClassDefFoundError: javax/mail/MessagingException java.lang.NoClassDefFoundError: javax/mail/MessagingException
at org.apache.logging.log4j.core.appender.SmtpAppender$Builder.lambda$build$0(SmtpAppender.java:288)
at java.base/java.util.Optional.orElseGet(Unknown Source)
at org.apache.logging.log4j.core.appender.SmtpAppender$Builder.build(SmtpAppender.java:288)
at org.apache.logging.log4j.core.appender.SmtpAppender$Builder.build(SmtpAppender.java:92)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:124)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
at org.apache.logging.log4j.core.LoggerContext.onChange(LoggerContext.java:757)
at org.apache.logging.log4j.core.util.AbstractWatcher$ReconfigurationRunnable.run(AbstractWatcher.java:93)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
2023-01-24 17:31:47,571 Log4j2-TF-3-ConfigurationFileWatcher-3 ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.SmtpAppender for element SMTP: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.SmtpAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.SmtpAppender
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:260)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:136)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
at org.apache.logging.log4j.core.LoggerContext.onChange(LoggerContext.java:757)
at org.apache.logging.log4j.core.util.AbstractWatcher$ReconfigurationRunnable.run(AbstractWatcher.java:93)
at java.base/java.lang.Thread.run(Unknown Source)
2023-01-24 17:31:47,575 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
2023-01-24 17:31:47,577 Log4j2-TF-3-ConfigurationFileWatcher-3 ERROR Null object returned for SMTP in Appenders.
2023-01-24 17:31:47,579 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG createAppenders(={})
2023-01-24 17:31:47,580 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2023-01-24 17:31:47,581 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG createAppenderRef(ref="Mailer", level="null", Filter=null)
2023-01-24 17:31:47,581 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
2023-01-24 17:31:47,582 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG LoggerConfig$RootLogger$Builder(additivity="null", level="INFO", levelAndRefs="null", includeLocation="null", ={Mailer}, ={}, Configuration(C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml), Filter=null)
2023-01-24 17:31:47,583 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
2023-01-24 17:31:47,584 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG createLoggers(={root})
2023-01-24 17:31:47,585 Log4j2-TF-3-ConfigurationFileWatcher-3 ERROR Unable to locate appender "Mailer" for logger config "root"
2023-01-24 17:31:47,586 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Configuration XmlConfiguration[location=C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml] initialized
2023-01-24 17:31:47,587 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Starting configuration XmlConfiguration[location=C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml]
2023-01-24 17:31:47,588 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Log4j2 ConfigurationScheduler starting 1 threads
2023-01-24 17:31:47,589 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Started configuration XmlConfiguration[location=C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml] OK.
2023-01-24 17:31:47,590 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Log4jBridgeHandler.propertyChange(): java.beans.PropertyChangeEvent[propertyName=config; oldValue=XmlConfiguration[location=C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml]; newValue=XmlConfiguration[location=C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml]; propagationId=null; source=org.apache.logging.log4j.core.LoggerContext#7674b62c]
2023-01-24 17:31:47,591 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Log4jBridgeHandler.propagateLogLevels(): XmlConfiguration[location=C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml]
2023-01-24 17:31:47,593 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Log4j2 ConfigurationScheduler shutting down threads in java.util.concurrent.ScheduledThreadPoolExecutor#6302a2c0[Running, pool size = 1, active threads
= 0, queued tasks = 1, completed tasks = 3]
2023-01-24 17:31:47,595 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Stopped XmlConfiguration[location=C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml] OK
2023-01-24 17:31:47,596 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Log4jBridgeHandler.propertyChange(): java.beans.PropertyChangeEvent[propertyName=config; oldValue=XmlConfiguration[location=C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml]; newValue=XmlConfiguration[location=C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml]; propagationId=null; source=org.apache.logging.log4j.core.LoggerContext#7674b62c]
2023-01-24 17:31:47,599 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Log4jBridgeHandler.propagateLogLevels(): XmlConfiguration[location=C:\Users\theo.lalande\Desktop\smtp\target\classes\log4j2.xml]
2023-01-24 17:31:47,602 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Registering MBean org.apache.logging.log4j2:type=6d5380c2
2023-01-24 17:31:47,603 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Registering MBean org.apache.logging.log4j2:type=6d5380c2,component=StatusLogger
2023-01-24 17:31:47,604 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Registering MBean org.apache.logging.log4j2:type=6d5380c2,component=ContextSelector
2023-01-24 17:31:47,606 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Registering MBean org.apache.logging.log4j2:type=6d5380c2,component=Loggers,name=
2023-01-24 17:31:47,606 Log4j2-TF-3-ConfigurationFileWatcher-3 DEBUG Reconfiguration completed for 6d5380c2 (org.apache.logging.log4j.core.LoggerContext#7674b62c) in 65 milliseconds.
I've tried plenty of things, but cannot mannage du make it work. Does anyone avec a clue?
Your are facing one of the side-effects of the gap between Java EE 8 and Jakarta EE 9 (it's a very disruptive renaming of classes): Spring Boot 3.x contains an implementation of Jakarta Mail 2.0, while the SMTP appender in Log4j2 Core requires and implementation of Java Mail 1.6.
To fill the gap, we published an alternative implementation of MailManager (the engine behind the SMTP appender) in the log4j-jakarta-smtp artifact. To use it, you just need to add it to your runtime classpath:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jakarta-smtp</artifactId>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta-activation</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.mail</groupId>
<artifactId>smtp</artifactId>
</exclusion>
</exclusions>
</dependency>
(the version is managed by Spring Boot).
Try replacing
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
with the following the dependencies
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
<scope>runtime</scope>
</dependency>
Related
when a try to start my pod of a spring boot application, I get stuck in the errors bellows:
2022-06-02 14:07:21,189 main DEBUG Apache Log4j Core 2.17.1 initializing configuration XmlConfiguration[location=jar:file:/usr/app/api-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/log4j2.xml]
2022-06-02 14:07:21,201 main DEBUG Installed 0 script engines
2022-06-02 14:07:21,201 main DEBUG PluginManager 'Core' found 127 plugins
2022-06-02 14:07:21,201 main DEBUG PluginManager 'Level' found 0 plugins
2022-06-02 14:07:21,204 main DEBUG PluginManager 'Lookup' found 16 plugins
2022-06-02 14:07:21,218 main DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
2022-06-02 14:07:21,230 main DEBUG PluginManager 'TypeConverter' found 26 plugins
2022-06-02 14:07:21,241 main DEBUG PatternLayout$Builder(pattern="%highlight{%-5p|%d{ISO8601}{GMT}|thread id:%tid|%X{Slf4jMDCFilter.UUID}| [%t] %logger{36} - %msg%n}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=blue, DEBUG=green bold, TRACE=blue}", PatternSelector=null, Configuration(jar:file:/usr/app/api-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/log4j2.xml), Replace=null, charset="UTF-8", alwaysWriteExceptions="null", disableAnsi="false", noConsoleNoAnsi="null", header="null", footer="null")
2022-06-02 14:07:21,241 main DEBUG PluginManager 'Converter' found 48 plugins
2022-06-02 14:07:21,288 main DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender].
2022-06-02 14:07:21,295 main DEBUG ConsoleAppender$Builder(target="SYSTEM_OUT", follow="null", direct="null", bufferedIo="null", bufferSize="null", immediateFlush="null", ignoreExceptions="null", PatternLayout(%highlight{%-5p|%d{ISO8601}{GMT}|thread id:%tid|%X{Slf4jMDCFilter.UUID}| [%t] %logger{36} - %msg%n}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=blue, DEBUG=green bold, TRACE=blue}), name="LogToConsole", Configuration(jar:file:/usr/app/api-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/log4j2.xml), Filter=null, ={})
2022-06-02 14:07:21,298 main DEBUG Starting OutputStreamManager SYSTEM_OUT.false.false
2022-06-02 14:07:21,298 main DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
2022-06-02 14:07:21,298 main DEBUG createAppenders(={LogToConsole})
2022-06-02 14:07:21,299 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2022-06-02 14:07:21,301 main DEBUG createAppenderRef(ref="LogToConsole", level="null", Filter=null)
2022-06-02 14:07:21,302 main DEBUG Building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig].
2022-06-02 14:07:21,303 main DEBUG createLogger(additivity="false", level="INFO", name="com.obs.dqsc.api", includeLocation="null", ={LogToConsole}, ={}, Configuration(jar:file:/usr/app/api-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/log4j2.xml), Filter=null)
2022-06-02 14:07:21,305 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2022-06-02 14:07:21,305 main DEBUG createAppenderRef(ref="LogToConsole", level="null", Filter=null)
2022-06-02 14:07:21,305 main DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
2022-06-02 14:07:21,306 main DEBUG createLogger(additivity="false", level="INFO", includeLocation="null", ={LogToConsole}, ={}, Configuration(jar:file:/usr/app/api-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/log4j2.xml), Filter=null)
2022-06-02 14:07:21,306 main DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
2022-06-02 14:07:21,307 main DEBUG createLoggers(={com.obs.dqsc.api, root})
2022-06-02 14:07:21,308 main DEBUG Configuration XmlConfiguration[location=jar:file:/usr/app/api-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/log4j2.xml] initialized
2022-06-02 14:07:21,308 main DEBUG Starting configuration XmlConfiguration[location=jar:file:/usr/app/api-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/log4j2.xml]
2022-06-02 14:07:21,308 main DEBUG Started configuration XmlConfiguration[location=jar:file:/usr/app/api-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/log4j2.xml] OK.
2022-06-02 14:07:21,310 main DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false.false-1
2022-06-02 14:07:21,310 main DEBUG OutputStream closed
2022-06-02 14:07:21,310 main DEBUG Shut down OutputStreamManager SYSTEM_OUT.false.false-1, all resources released: true
2022-06-02 14:07:21,310 main DEBUG Appender DefaultConsole-1 stopped with status true
2022-06-02 14:07:21,311 main DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration#6073f712 OK
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.lang.InternalError: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.platform.Metrics.systemMetrics(Metrics.java:65)
at java.base/jdk.internal.platform.Container.metrics(Container.java:43)
at jdk.management/com.sun.management.internal.OperatingSystemImpl.<init>(OperatingSystemImpl.java:48)
at jdk.management/com.sun.management.internal.PlatformMBeanProviderImpl.getOperatingSystemMXBean(PlatformMBeanProviderImpl.java:279)
at jdk.management/com.sun.management.internal.PlatformMBeanProviderImpl$3.nameToMBeanMap(PlatformMBeanProviderImpl.java:198)
at java.management/java.lang.management.ManagementFactory.lambda$getPlatformMBeanServer$0(ManagementFactory.java:487)
at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:273)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1766)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at java.management/java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:488)
at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:140)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:637)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:699)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:716)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:270)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
at org.apache.commons.logging.LogAdapter$Log4jLog.<clinit>(LogAdapter.java:155)
at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:122)
at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:89)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59)
at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:201)
at com.obs.dqsc.api.ApiApplication.main(ApiApplication.java:37)
... 8 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/jdk.internal.platform.Metrics.systemMetrics(Metrics.java:61)
... 38 more
Caused by: java.lang.ExceptionInInitializerError
at java.base/jdk.internal.platform.CgroupSubsystemFactory.create(CgroupSubsystemFactory.java:107)
at java.base/jdk.internal.platform.CgroupMetrics.getInstance(CgroupMetrics.java:167)
... 43 more
Caused by: java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:208)
at java.base/sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:260)
at java.base/java.nio.file.Path.of(Path.java:147)
at java.base/java.nio.file.Paths.get(Paths.java:69)
at java.base/jdk.internal.platform.CgroupUtil.lambda$readStringValue$1(CgroupUtil.java:66)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
at java.base/jdk.internal.platform.CgroupUtil.readStringValue(CgroupUtil.java:68)
at java.base/jdk.internal.platform.CgroupSubsystemController.getStringValue(CgroupSubsystemController.java:65)
at java.base/jdk.internal.platform.CgroupSubsystemController.getLongValue(CgroupSubsystemController.java:124)
at java.base/jdk.internal.platform.cgroupv1.CgroupV1Subsystem.getLongValue(CgroupV1Subsystem.java:272)
at java.base/jdk.internal.platform.cgroupv1.CgroupV1Subsystem.getHierarchical(CgroupV1Subsystem.java:218)
at java.base/jdk.internal.platform.cgroupv1.CgroupV1Subsystem.setPath(CgroupV1Subsystem.java:201)
at java.base/jdk.internal.platform.cgroupv1.CgroupV1Subsystem.setSubSystemControllerPath(CgroupV1Subsystem.java:173)
at java.base/jdk.internal.platform.cgroupv1.CgroupV1Subsystem.lambda$initSubSystem$5(CgroupV1Subsystem.java:113)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at java.base/jdk.internal.platform.cgroupv1.CgroupV1Subsystem.initSubSystem(CgroupV1Subsystem.java:113)
at java.base/jdk.internal.platform.cgroupv1.CgroupV1Subsystem.<clinit>(CgroupV1Subsystem.java:47)
I'm wondering if that could be because I'm using log4j2 within springAOP with a generic method that uses Reflection api to trace logs.
this errors happens occasionally, sometimes it auto-correct itself and I don't know why, there is also a mention of UnixFileSystem.java in the exception but I don't know what does it mean, it might be a problem on the server and not related to the application?
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>
I just experienced what seems to be a similar problem. In my case, I was able to receive application logs, but with what appeared to be a default log4j2 config. The logs were INFO level. None of the levels set for loggers in the log4j2 config (XML) were being applied. I saw a very similar output in the startup logs as posted by the OP, including the message about "shutting down OutputStreamManager".
Mine is a spring-boot application and I was able to resolve the problem by disabling the spring-boot LoggingSystem. I added this system variable to my startup command:
-Dorg.springframework.boot.logging.LoggingSystem=none
Once I did that, the logging worked as expected, according to the levels set in my log4j2 XML config. It appears to be spring-boot hijacking the log system, rather than a conflict between SLF4J an LOG4J2.
Note that I still see the same logging startup messages -- the OutputStreamManager is still shutting down. Speculation: this is normal behavior, possibly just shutting down the bootstrap logger that prints the log4j2 initialization process.
Versions:
log4j: 2.13.3
slf4j: 1.7.30
spring-boot: 2.2.7-RElEASE
I am trying to log in JSON format through log4j2.
This is my log4j2.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug" name="MyApp" packages="org.apache.logging.log4j.core.layout.JSONLayout">
<Appenders>
<RollingRandomAccessFile name="RollingRandomAccessFile" fileName="logs/app3.log"
filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz" append="false">
<JsonLayout/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="RollingRandomAccessFile"/>
</Root>
</Loggers>
</Configuration>
These are the dependencies I have used:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>net.logstash.log4j</groupId>
<artifactId>jsonevent-layout</artifactId>
<version>1.7</version>
</dependency><dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
When I run the program I get an error as follows:
543 main ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.layout.JsonLayout for element JsonLayout.
Debug:
2016-05-09 16:06:04,909 main DEBUG Initializing configuration XmlConfiguration[location=/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml]
2016-05-09 16:06:04,916 main DEBUG Installed script engines
2016-05-09 16:06:05,717 main DEBUG Oracle Nashorn Version: 1.8.0_91, Language: ECMAScript, Threading: Not Thread Safe, Compile: true, Names: {nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript}
2016-05-09 16:06:05,823 main DEBUG Took 0.104995 seconds to load 14 plugins from package org.apache.logging.log4j.core.layout
2016-05-09 16:06:05,824 main DEBUG PluginManager 'Core' found 97 plugins
2016-05-09 16:06:05,824 main DEBUG PluginManager 'Level' found 0 plugins
2016-05-09 16:06:05,831 main DEBUG No scheduled items
2016-05-09 16:06:05,835 main DEBUG PluginManager 'Lookup' found 13 plugins
2016-05-09 16:06:05,837 main DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.JsonLayout].
2016-05-09 16:06:05,853 main DEBUG PluginManager 'TypeConverter' found 23 plugins
2016-05-09 16:06:05,863 main DEBUG createLayout(locationInfo="false", properties="false", complete="false", compact="false", eventEol="false", charset="UTF-8")
2016-05-09 16:06:05,864 main ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.layout.JsonLayout for element JSONLayout.
2016-05-09 16:06:05,865 main DEBUG Building Plugin[name=TimeBasedTriggeringPolicy, class=org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy].
2016-05-09 16:06:05,867 main DEBUG createPolicy(interval="null", modulate="null")
2016-05-09 16:06:05,868 main DEBUG Building Plugin[name=SizeBasedTriggeringPolicy, class=org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy].
2016-05-09 16:06:05,869 main DEBUG createPolicy(size="250 MB")
2016-05-09 16:06:05,872 main DEBUG Building Plugin[name=Policies, class=org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy].
2016-05-09 16:06:05,882 main DEBUG createPolicy(={TimeBasedTriggeringPolicy(nextRolloverMillis=0, interval=1, modulate=false), SizeBasedTriggeringPolicy(size=262144000)})
2016-05-09 16:06:05,882 main DEBUG Building Plugin[name=DefaultRolloverStrategy, class=org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy].
2016-05-09 16:06:05,887 main DEBUG createStrategy(max="20", min="null", fileIndex="null", compressionLevel="null", ={}, stopCustomActionsOnError="true", Configuration(/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml))
2016-05-09 16:06:05,888 main DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender].
2016-05-09 16:06:05,892 main DEBUG createAppender(fileName="logs/app3.log", filePattern="logs/${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz", append="false", name="RollingRandomAccessFile", immediateFlush="null", bufferSize="null", Policies(CompositeTriggeringPolicy(policies=[TimeBasedTriggeringPolicy(nextRolloverMillis=0, interval=1, modulate=false), SizeBasedTriggeringPolicy(size=262144000)])), DefaultRolloverStrategy(DefaultRolloverStrategy(min=1, max=20)), JSONLayout(null), Filter=null, ignoreExceptions="null", advertise="null", advertiseURI="null", Configuration(/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml))
2016-05-09 16:06:05,893 main INFO Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
2016-05-09 16:06:05,894 main DEBUG PluginManager 'Converter' found 38 plugins
2016-05-09 16:06:05,895 main DEBUG Starting OutputStreamManager SYSTEM_OUT.false-2
2016-05-09 16:06:05,909 main DEBUG Starting RollingRandomAccessFileManager logs/app3.log
2016-05-09 16:06:05,914 main DEBUG PluginManager 'FileConverter' found 2 plugins
2016-05-09 16:06:05,935 main DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
2016-05-09 16:06:05,936 main DEBUG createAppenders(={RollingRandomAccessFile})
2016-05-09 16:06:05,936 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2016-05-09 16:06:05,937 main DEBUG createAppenderRef(ref="RollingRandomAccessFile", level="null", Filter=null)
2016-05-09 16:06:05,937 main DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
2016-05-09 16:06:05,938 main DEBUG createLogger(additivity="null", level="TRACE", includeLocation="null", ={RollingRandomAccessFile}, ={}, Configuration(/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml), Filter=null)
2016-05-09 16:06:05,941 main DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
2016-05-09 16:06:05,943 main DEBUG createLoggers(={root})
2016-05-09 16:06:05,944 main DEBUG Configuration XmlConfiguration[location=/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml] initialized
2016-05-09 16:06:05,952 main DEBUG Starting configuration XmlConfiguration[location=/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml]
2016-05-09 16:06:05,952 main DEBUG Started configuration XmlConfiguration[location=/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml] OK.
2016-05-09 16:06:05,953 main DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false-1
2016-05-09 16:06:05,953 main DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration#7de26db8 OK
2016-05-09 16:06:06,027 main DEBUG Registering MBean org.apache.logging.log4j2:type=1a6c5a9e
2016-05-09 16:06:06,030 main DEBUG Registering MBean org.apache.logging.log4j2:type=1a6c5a9e,component=StatusLogger
2016-05-09 16:06:06,032 main DEBUG Registering MBean org.apache.logging.log4j2:type=1a6c5a9e,component=ContextSelector
2016-05-09 16:06:06,034 main DEBUG Registering MBean org.apache.logging.log4j2:type=1a6c5a9e,component=Loggers,name=
2016-05-09 16:06:06,036 main DEBUG Registering MBean org.apache.logging.log4j2:type=1a6c5a9e,component=Appenders,name=RollingRandomAccessFile
2016-05-09 16:06:06,041 main DEBUG Reconfiguration complete for context[name=1a6c5a9e] at URI /home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml (org.apache.logging.log4j.core.LoggerContext#732c2a62) with optional ClassLoader: null
2016-05-09 16:06:06,041 main DEBUG Shutdown hook enabled. Registering a new one.
16-05-09 16:06:06,043 main DEBUG LoggerContext[name=1a6c5a9e, org.apache.logging.log4j.core.LoggerContext#732c2a62] started OK.
Is there a dependency I am missing out or this some other problem? Please suggest possible things I can try for solving this problem. If you know a better solution to write logs in Logstash Json format you may suggest.
I suspect you are missing one of the Jackson dependencies.
You have jackson-core-asl, I think you need these three:
com.fasterxml.jackson.core:jackson-core:jar:2.6.3
com.fasterxml.jackson.core:jackson-databind:jar:2.6.3
com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0
The ultimate source of truth for dependencies is the dependency tree of the Log4j 2 implementation module.
You may be able to get more details on the problem by setting <Configuration status="debug" ... in your configuration.
When using the RTC SDK normally in an application, I can turn off the logging in that layer using Log4j with the following code:
// Only show warnings for IBM dependencies
Logger.getLogger("com.ibm").setLevel(Level.WARN);
Logger.getLogger("com.ibm").setAdditivity(false);
Logger.getRootLogger().setLevel(Level.DEBUG);
When trying to convert over to SpringBoot, I add just the basic SpringBoot package and I get all sorts of debug information from the RTC SDK. Even if I have only the root logger set to FATAL and have not settings anywhere else for logging.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
As soon as I add the dependency, (without even having the #SpringBootApplication annotation or even SpringApplication.run(Main.class, args), it starts spewing out RTC log information like the following:
16:14:20.161 [main] DEBUG c.i.t.r.c.i.u.InternalTeamPlatform - Thread[main,5,main]
16:14:20.164 [main] DEBUG c.i.t.r.c.i.u.InternalTeamPlatform - start asBundlefalse
16:14:20.164 [main] DEBUG c.i.t.r.c.i.u.InternalTeamPlatform - set start true
16:14:22.387 [main] DEBUG c.i.t.r.t.client.RemoteTeamServer - Entering setCredentials(userid=, password=)
16:14:22.387 [main] DEBUG c.i.t.r.t.client.RemoteTeamServer - Entering closeHttpClient
16:14:22.387 [main] DEBUG c.i.t.r.t.client.RemoteTeamServer - Value of _httpclient: null
16:14:22.408 [main] DEBUG c.i.t.r.t.client.RemoteTeamServer - httpclient already closed
16:14:22.410 [main] DEBUG c.i.t.r.t.client.RemoteTeamServer - Entering createTeamService
16:14:22.410 [main] DEBUG c.i.t.r.t.client.RemoteTeamServer - creating RemoteTeamService from com.ibm.team.repository.common.internal.IRepositoryRemoteService
16:14:22.420 [main] DEBUG c.i.t.r.t.client.RemoteTeamServer - Entering createTeamService
16:14:22.420 [main] DEBUG c.i.t.r.t.client.RemoteTeamServer - creating RemoteTeamService from com.ibm.team.repository.common.service.IQueryService
16:14:22.424 [main] DEBUG c.i.t.r.t.client.RemoteTeamServer - Entering createTeamService
16:14:22.424 [main] DEBUG c.i.t.r.t.client.RemoteTeamServer - creating RemoteTeamService from com.ibm.team.repository.common.service.IExternalUserRegistryService
My question is, how can I turn this excess logging off? It is quite annoying and not useful to me.
As my colleague suggested in his comment:
you have to include this inside of your pom underneath the dependency tag:
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
My Google foo is letting me down today! I am trying to configure log4j2 so that I can access the loggers via JMX and change their log levels.
However, when I hook everything up, none of the loggers show up in the JMX tree (or log4j-jmx-gui) as shown in the log4j2 JMX docs. Only the log4j2 ContextSelector and StatusLogger in the JConsole attribute tree and the StatusLogger tab in the log4j-jmx-gui (stand-alone or as a plugin) show up. No LoggerContext elements.
I've googled and not come up with anything! That probably means I'm missing something somewhere. Any help would be greatly appreciated by me and wall which I'm banging my head against :)
I'm using Log4j2 beta9 with Java 1.6.0_45-b06 on win7. I have tried it on Java 7 and it results in the same behaviour.
The log4j2 dependencies being used:
log4j-api-2.0-beta9.jar
log4j-core-2.0-beta9.jar
My log4j2.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="debug">
<Appenders>
<Console name="log-test" target="SYSTEM_OUT">
<PatternLayout pattern="%d{DATE} %-5p LJX2 %c{1}: %m%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="top.Log4J2TestApp" level="debug" additivity="false">
<AppenderRef ref="log-test" />
</Logger>
<Root level="trace">
<AppenderRef ref="log-test" />
</Root>
</Loggers>
</Configuration>
My test program:
package top;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Log4J2TestApp {
public static void main(String[] args) {
System.out.println("******** Started ZZZ ****************");
Logger log = LogManager.getLogger(Log4J2TestApp.class);
int cnt = 0;
while (true) {
log.warn("=========== Test message: {} ================", cnt++);
Thread.sleep(1000);
}
}
}
The output of the test program looks like this:
******** Started ZZZ ****************
2013-11-06 15:07:29,720 DEBUG Generated plugins in 0.000020959 seconds
2013-11-06 15:07:29,733 DEBUG Calling createLayout on class org.apache.logging.log4j.core.layout.PatternLayout for element PatternLayout with params(pattern="%d{DATE} %-5p LJX2 %c{1}: %m%n", Configuration(log4j2.xml), null, charset="null",alwaysWriteExceptions="null")
2013-11-06 15:07:29,735 DEBUG Generated plugins in 0.000013687 seconds
2013-11-06 15:07:29,737 DEBUG Calling createAppender on class org.apache.logging.log4j.core.appender.ConsoleAppender for element Console with params(PatternLayout(%d{DATE} %-5p LJX2 %c{1}: %m%n), null, target="SYSTEM_OUT", name="log-test",follow="null", ignoreExceptions="null")
2013-11-06 15:07:29,739 DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream2013-11-06 15:07:29,740 DEBUG Calling createAppenders on class org.apache.logging.log4j.core.config.plugins.AppendersPlugin for element Appenders with params(Appenders={log-test})
2013-11-06 15:07:29,742 DEBUG Generated plugins in 0.000012832 seconds
2013-11-06 15:07:29,743 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element AppenderRef with params(ref="log-test", level="null", null)
2013-11-06 15:07:29,746 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig for element Logger with params(additivity="false", level="debug", name="top.Log4J2TestApp", includeLocation="null", AppenderRef={log-test}, Properties={}, Configuration(log4j2.xml), null)
2013-11-06 15:07:29,749 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element AppenderRef with params(ref="log-test", level="null", null)
2013-11-06 15:07:29,751 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger for element Root with params(additivity="null", level="trace", includeLocation="null", AppenderRef={log-test}, Properties={}, Configuration(log4j2.xml), null)
2013-11-06 15:07:29,754 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.plugins.LoggersPluginfor element Loggers with params(Loggers={top.Log4J2TestApp, root})
2013-11-06 15:07:29,755 DEBUG Reconfiguration completed
06 Nov 2013 15:07:29,763 WARN LJX2 Log4J2TestApp: =========== Test message: 0 ================
....
06 Nov 2013 15:07:36,766 WARN LJX2 Log4J2TestApp: =========== Test message: 7 ================
2013-11-06 15:07:51,450 DEBUG ServletContext not present - WebLookup not added
2013-11-06 15:07:51,451 DEBUG Shutting down OutputStreamManager SYSTEM_OUT
The StatusLogger tab in the log4j-jmx-gui does have one exception but it would seem to have nothing to do with the loggers.
2013-11-06 15:41:01,403 WARN Multiple logging implementations found:
Factory: org.apache.logging.log4j.core.impl.Log4jContextFactory, Weighting: 10
Using factory: org.apache.logging.log4j.core.impl.Log4jContextFactory
2013-11-06 15:41:01,505 WARN JmDNS or serviceInfo class not found java.lang.ClassNotFoundException: javax.jmdns.JmDNS
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:171)
at org.apache.logging.log4j.core.net.MulticastDNSAdvertiser.initializeJMDNS(MulticastDNSAdvertiser.java:228)
at org.apache.logging.log4j.core.net.MulticastDNSAdvertiser.<clinit>(MulticastDNSAdvertiser.java:41)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:171)
at org.apache.logging.log4j.core.config.plugins.PluginManager.decode(PluginManager.java:241)
at org.apache.logging.log4j.core.config.plugins.PluginManager.collectPlugins(PluginManager.java:152)
at org.apache.logging.log4j.core.config.plugins.PluginManager.collectPlugins(PluginManager.java:130)
at org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:116)
at org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:102)
at org.apache.logging.log4j.core.layout.PatternLayout.createPatternParser(PatternLayout.java:183)
at org.apache.logging.log4j.core.layout.PatternLayout.<init>(PatternLayout.java:115)
at org.apache.logging.log4j.core.layout.PatternLayout.createLayout(PatternLayout.java:219)
at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:51)
at org.apache.logging.log4j.core.LoggerContext.<init>(LoggerContext.java:63)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:217)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:114)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:81)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:83)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:34)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:387)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:332)
at top.Log4J2TestApp.main(Log4J2TestApp.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
2013-11-06 15:41:01,612 DEBUG Generated plugins in 0.000017537 seconds
2013-11-06 15:41:01,625 DEBUG Calling createLayout on class org.apache.logging.log4j.core.layout.PatternLayout for element PatternLayout with params(pattern="%d{DATE} %-5p LJX2 %c{1}: %m%n", Configuration(log4j2.xml), null, charset="null", alwaysWriteExceptions="null")
2013-11-06 15:41:01,627 DEBUG Generated plugins in 0.000011977 seconds
2013-11-06 15:41:01,629 DEBUG Calling createAppender on class org.apache.logging.log4j.core.appender.ConsoleAppender for element Console with params(PatternLayout(%d{DATE} %-5p LJX2 %c{1}: %m%n), null, target="SYSTEM_OUT", name="log-test", follow="null", ignoreExceptions="null")
2013-11-06 15:41:01,631 DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream
2013-11-06 15:41:01,632 DEBUG Calling createAppenders on class org.apache.logging.log4j.core.config.plugins.AppendersPlugin for element Appenders with params(Appenders={log-test})
2013-11-06 15:41:01,633 DEBUG Generated plugins in 0.000011977 seconds
2013-11-06 15:41:01,635 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element AppenderRef with params(ref="log-test", level="null", null)
2013-11-06 15:41:01,637 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig for element Logger with params(additivity="false", level="debug", name="top.Log4J2TestApp", includeLocation="null", AppenderRef={log-test}, Properties={}, Configuration(log4j2.xml), null)
2013-11-06 15:41:01,640 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element AppenderRef with params(ref="log-test", level="null", null)
2013-11-06 15:41:01,642 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger for element Root with params(additivity="null", level="trace", includeLocation="null", AppenderRef={log-test}, Properties={}, Configuration(log4j2.xml), null)
2013-11-06 15:41:01,644 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.plugins.LoggersPlugin for element Loggers with params(Loggers={top.Log4J2TestApp, root})
2013-11-06 15:41:01,646 DEBUG Reconfiguration completed
Your config looks good, the only thing a bit suspicious is the error. The error does seem to occur in the LoggerContext constructor, so it may be related after all.
You may have found a bug. Would you mind reporting this issue in the log4j2 issue tracker so the log4j team can look at it?
Log4j2 uses ClassLoaderContextSelector as ContextSelector by default. In some cases (it is not clear for me, may be for simple applications like yours) it returns nothing as getLoggerContexts() method call result. No logger contexts - nothing no show, so LoggerContext category doesn't present in the tree. It can be fixed by selecting another ContextSelector implementation. I used org.apache.logging.log4j.core.selector.BasicContextSelector for this purpose. It can be set using system property named "Log4jContextSelector". See docs for more info.
It solves my problem, I hope it helps to solve yours too.