spring Logback error coming when starting spring application - java

Below logback error is coming when starting the spring application which is deployed in Kubernetes.
2022-04-20 13:47:25.928 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Logback configuration error detected:
ERROR in c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy#1248276879 -
Unexpected exception while waiting for compression job to finish
java.lang.InterruptedException at
org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
at
org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:82)
at
org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
at
org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:117)
at
org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:290)
at
org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:263)
at
org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:226)
at
org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:199)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at
org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
at
org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at
org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
at com.dt.Application.main(Application.java:20) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at
org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Logback-spring configuration:-
<appender name="FILE-JSON-LIBS"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/${dtlogname:-${ACTIVE_APP}}-${envname:-${ENV}}-libs-json-${HOSTNAME}.log</file>
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<timeZone>UTC</timeZone>
<timestampPattern>dd-MM-yyyy HH:mm:ss:SSS</timestampPattern>
<shortenedLoggerNameLength>25</shortenedLoggerNameLength>
<fieldNames>
<timestamp>requestTimeStamp</timestamp>
<thread>threadId</thread>
<logger>logger</logger>
<stackTrace>stackTrace</stackTrace>
<version>[ignore]</version>
<levelValue>[ignore]</levelValue>
</fieldNames>
<includeMdcKeyName>REQUEST_ID</includeMdcKeyName>
<includeMdcKeyName>CORRELATION_ID</includeMdcKeyName>
<includeMdcKeyName>COUNTRY</includeMdcKeyName>
<includeMdcKeyName>LANGUAGE</includeMdcKeyName>
<includeMdcKeyName>CHANNEL</includeMdcKeyName>
<mdcKeyFieldName>REQUEST_ID=requestId</mdcKeyFieldName>
<mdcKeyFieldName>CORRELATION_ID=correlationId</mdcKeyFieldName>
<mdcKeyFieldName>COUNTRY=country</mdcKeyFieldName>
<mdcKeyFieldName>LANGUAGE=language</mdcKeyFieldName>
<mdcKeyFieldName>CHANNEL=channel</mdcKeyFieldName>
<includeContext>false</includeContext>
<customFields>{"serviceId":"${ACTIVE_APP}"}</customFields>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>
${LOG_DIR}/${dtlogname:-${ACTIVE_APP}}-${envname:-${ENV}}-libs-json-${HOSTNAME}.%d{yyyy-MM-dd}.%i.gz
</fileNamePattern>
<maxFileSize>1GB</maxFileSize>
<totalSizeCap>10GB</totalSizeCap>
<!-- keep 30 days worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
Any idea to overcome this error will be helpful as it stops the main application.

You have a maximum filesize of 1GB and specify gzip compression. Depending on your resource configuration in the pod this can lead to quite a long time for performing the compression.
You can either increase the resources or, probably better, reduce the max file size to 100mb.

Related

logback.xml missing in project created with STS and Spring boot

I created a Spring boot web project within STS, used last version
I am getting error that logback.xml is missing, but I created on src/main/resources
03:37:08,276 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
03:37:08,276 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
03:37:08,277 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/D:/Sites/sts/GoogleCustomSearchBoot/target/classes/logback.xml]
03:37:08,385 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
03:37:08,388 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
03:37:08,396 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
03:37:08,445 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
03:37:08,446 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
03:37:08,447 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
03:37:08,448 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator#61a485d2 - Registering current configuration as safe fallback point
Logging system failed to initialize using configuration from 'classpath:/logback.xml'
java.io.FileNotFoundException: class path resource [/logback.xml] cannot be resolved to URL because it does not exist
at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:135)
at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:307)
at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at com.example.GoogleCustomSearchBootApplication.main(GoogleCustomSearchBootApplication.java:10)
03:37:08.825 [main] DEBUG o.s.b.l.ClasspathLoggingApplicationListener - Application failed to start with classpath: [file:/D:/Sites/sts/GoogleCustomSearchBoot/target/classes/, file:/D:/java/m2/org/springframework/boot/spring-boot-starter-web/1.5.3.RELEASE/spring-boot-starter-web-1.5.3.RELEASE.jar, file:/D:/java/m2/org/springframework/boot/spring-boot-starter/1.5.3.RELEASE/spring-boot-starter-1.5.3.RELEASE.jar, file:/D:/java/m2/org/springframework/boot/spring-boot/1.5.3.RELEASE/spring-boot-1.5.3.RELEASE.jar, file:/D:/java/m2/org/springframework/boot/spring-boot-autoconfigure/1.5.3.RELEASE/spring-boot-autoconfigure-1.5.3.RELEASE.jar, file:/D:/java/m2/org/springframework/boot/spring-boot-starter-logging/1.5.3.RELEASE/spring-boot-starter-logging-1.5.3.RELEASE.jar, file:/D:/java/m2/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar, file:/D:/java/m2/ch/qos/logback/logback-core/1.1.11/logback-core-1.1.11.jar, file:/D:/java/m2/org/slf4j/jcl-over-slf4j/1.7.25/jcl-over-slf4j-1.7.25.jar, file:/D:/java/m2/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar, file:/D:/java/m2/org/slf4j/log4j-over-slf4j/1.7.25/log4j-over-slf4j-1.7.25.jar, file:/D:/java/m2/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar, file:/D:/java/m2/org/springframework/boot/spring-boot-starter-tomcat/1.5.3.RELEASE/spring-boot-starter-tomcat-1.5.3.RELEASE.jar, file:/D:/java/m2/org/apache/tomcat/embed/tomcat-embed-core/8.5.14/tomcat-embed-core-8.5.14.jar, file:/D:/java/m2/org/apache/tomcat/embed/tomcat-embed-el/8.5.14/tomcat-embed-el-8.5.14.jar, file:/D:/java/m2/org/apache/tomcat/embed/tomcat-embed-websocket/8.5.14/tomcat-embed-websocket-8.5.14.jar, file:/D:/java/m2/org/hibernate/hibernate-validator/5.3.5.Final/hibernate-validator-5.3.5.Final.jar, file:/D:/java/m2/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar, file:/D:/java/m2/org/jboss/logging/jboss-logging/3.3.1.Final/jboss-logging-3.3.1.Final.jar, file:/D:/java/m2/com/fasterxml/classmate/1.3.3/classmate-1.3.3.jar, file:/D:/java/m2/com/fasterxml/jackson/core/jackson-databind/2.8.8/jackson-databind-2.8.8.jar, file:/D:/java/m2/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0.jar, file:/D:/java/m2/com/fasterxml/jackson/core/jackson-core/2.8.8/jackson-core-2.8.8.jar, file:/D:/java/m2/org/springframework/spring-web/4.3.8.RELEASE/spring-web-4.3.8.RELEASE.jar, file:/D:/java/m2/org/springframework/spring-aop/4.3.8.RELEASE/spring-aop-4.3.8.RELEASE.jar, file:/D:/java/m2/org/springframework/spring-beans/4.3.8.RELEASE/spring-beans-4.3.8.RELEASE.jar, file:/D:/java/m2/org/springframework/spring-context/4.3.8.RELEASE/spring-context-4.3.8.RELEASE.jar, file:/D:/java/m2/org/springframework/spring-webmvc/4.3.8.RELEASE/spring-webmvc-4.3.8.RELEASE.jar, file:/D:/java/m2/org/springframework/spring-expression/4.3.8.RELEASE/spring-expression-4.3.8.RELEASE.jar, file:/D:/java/m2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar, file:/D:/java/m2/org/springframework/spring-core/4.3.8.RELEASE/spring-core-4.3.8.RELEASE.jar, file:/D:/java/m2/org/springframework/boot/spring-boot-configuration-processor/1.5.3.RELEASE/spring-boot-configuration-processor-1.5.3.RELEASE.jar, file:/D:/java/m2/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar, file:/D:/java/m2/joda-time/joda-time/2.9.9/joda-time-2.9.9.jar]
03:37:08.830 [main] ERROR o.s.boot.SpringApplication - Application startup failed
java.lang.IllegalStateException: java.io.FileNotFoundException: class path resource [/logback.xml] cannot be resolved to URL because it does not exist
at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:315)
at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at com.example.GoogleCustomSearchBootApplication.main(GoogleCustomSearchBootApplication.java:10)
Caused by: java.io.FileNotFoundException: class path resource [/logback.xml] cannot be resolved to URL because it does not exist
at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:135)
at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:307)
... 13 common frames omitted
I am attaching the project structure, I am including logback.xml
EDIT: I added debug="true" into my logback.xml file and logs show more things now, I just updated also. I can see logback.xml is found first, but in some point it is required again, but this time is not found.
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
I run into this same problem. In my case, the pom.xml was filtering files so it didn't see the .xml logback file.
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
<includes>
<include>**/*.jpg</include>
<include>**/*.properties</include>
</includes>
</resource>
You can include the .xml to includes session.
You have configured the logging.config property with the value classpath:logback.xml but there's no logback.xml file on the classpath.
You either need to provide a logback.xml configuration file or remove the configuration of logging.config and allow Boot to use its default Logback configuration.
Last version working seem to be 1.2.8.
Spring boot 1.3 and 1.4 don't work at all, in my windows machine.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
If you are using Maven to build your application you need to make sure that you tell Maven to include the resources folder in your jar.
I ran into this problem and wrote an article in our tech blog called Switching logging to logback. blog(dot)artifact-software(dot)com(slash)tech is the website.
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
needs to be in the build section to get test resources into your test setup.
A similar section needs to be added to get it into your production jar.

Location of logback default file appender

I have a J2EE web application with logback as the logging function
and use Tomcat 7 as the server.
I am using the logback ConsoleAppender right now, so I can go to
/var/log/tomcat7/catalina.out to check the log.
Right now, I want to move the log into a file. I will use a RollingFileAppender to save the log.
I DO NOT want to use a absolute path like:
<appender name="FILE" class="xxx.RollingFileAppender">
<file>/var/log/testFile1.log</file>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
I DO NOT want to use a system environment variable, either, like:
<appender name="FILE" class="xxx.RollingFileAppender">
<file>{LOG_LOCATION}\testFile2.log</file>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
If I only write the name of log file in the tag, like:
<appender name="FILE" class="xxx.RollingFileAppender">
<file>testFile3.log</file>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
I will receive the error:
21:29:45,265 |-ERROR in ch.qos.logback.core.FileAppender[TEST_LOG] - openFile(testFile3.log,true) call failed. java.io.FileNotFoundException: testFile3.log (Permission denied)
at java.io.FileNotFoundException: testFile3.log (Permission denied)
at at java.io.FileOutputStream.open(Native Method)
at at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at at ch.qos.logback.core.recovery.ResilientFileOutputStream.<init>(ResilientFileOutputStream.java:28)
at at ch.qos.logback.core.FileAppender.openFile(FileAppender.java:149)
at at ch.qos.logback.core.FileAppender.start(FileAppender.java:108)
at at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:96)
at at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:317)
at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:196)
at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:182)
at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:149)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:135)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:49)
at at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148)
at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
at at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
at at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
at at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:657)
at at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:282)
at at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
at at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
at at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at at java.lang.Thread.run(Thread.java:744)
Can I create a log file only with its name?
And if so, where is the default location for the logback log file in Tomcat 7 server?
You want a relative path. Specify <file>./testFile3.log</file>
Check where this gets created by running once.
Note that this could be relative to the location used for launching the application.

Log4j2 WebLookup

I'm using log4j2 (2.0.2) in a servlet 3.0 web application, running in Tomcat 8.0.12. I'm trying to use the weblookup to get the web app context path to use as part of the log file name. (We run the same war file under several different contexts using properties to configure it).
The log4j2.xml file includes
<RollingFile name="Web" fileName="/srv/dnsnet/logs/web-${web:contextPath}.logfile" filePattern="/srv/dnsnet/logs/web-${web:contextPath}-%d{yyyy-MM-dd}-%i.log.gz" append="true" immediateFlush="false">
<PatternLayout>
<Pattern>%d %-5p [%25.25t] %40.40c{3.} %15X{sysid} %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy max="8"/>
</RollingFile>
But the web:contextPath does not get resolved. I have got log4j-web-2.0.2.jar in my web app. I added some messages to the WebLookup class, and the problem is that the external context of the LoggerContext is null.
So I tried to see where the LoggerContext is created. The stack trace when the LoggerContext constructor is called is
at org.apache.logging.log4j.core.LoggerContext.<init>(LoggerContext.java:114)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:113)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:80)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:82)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:269)
at org.apache.logging.log4j.jcl.LogFactoryImpl$PrivateManager.getContext(LogFactoryImpl.java:108)
at org.apache.logging.log4j.jcl.LogFactoryImpl.getLoggersMap(LogFactoryImpl.java:52)
at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:43)
at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:75)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
at org.apache.myfaces.webapp.AbstractMyFacesListener.<clinit>(AbstractMyFacesListener.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:433)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
at org.apache.catalina.core.ApplicationContext.addListener(ApplicationContext.java:1231)
at org.apache.catalina.core.ApplicationContextFacade.addListener(ApplicationContextFacade.java:647)
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:110)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5164)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1686)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745
But the ClassLoaderContextSelector always passes null for the external context. So it looks as though I'm missing something.
Can anyone suggest what I'm doing wrong, or missing? Do I have to specify a different ContextSelector?
You may have found a bug in log4j. I suspect it is the combination of Commons Logging and the WebLookup that does not work. Can you verify if this is the case (check if the WebLookup works if your application uses the log4j 2 API instead of Commons Logging) and file a bug report in the log4j2 Jira issue tracker?

How to get the errors message with spring mvc in tomcat's catalina.out

I request a test link https://terran.gamebox.com/facebook/issueOrder.jhtml?amount=5&gameId=1&serverId=1&role=role
I can see the message in page
but the exception did not show in catalina.out
This is my configure file
<bean id="exceptionResolver" class="com.gamebox.HandlerException">
HandlerException implements HandlerExceptionResolver
I must point that I can get the other controller's exception such as null pointer exception
I guess it's a spring internal exception, but I need capture all exception in catalina.out file.
I create a #Service dependence in a #Controller, then delete the #Service's class file.
When I started the tomcat, everything is OK, I request this controller, I got the exception message, but the catalina.out show nothing. The tomcat ran in Run mode.
I paste the response message, because this mvc's action will fix next day with this bug, but I will trace nothing in my platform when I use a ajax with mvc in future if it doesn't show in catalina.out and I will be defficult to find nothing.
I am sure it involved transactionManager
java.lang.ClassNotFoundException: com.gamebox.service.FacebookPayOrderService
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
java.lang.Class.getDeclaredFields0(Native Method)
java.lang.Class.privateGetDeclaredFields(Class.java:2300)
java.lang.Class.getDeclaredFields(Class.java:1745)
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:374)
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:322)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:846)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:498)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
org.springframework.web.method.HandlerMethod.createWithResolvedBean(HandlerMethod.java:220)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:240)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:56)
org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:298)
org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1091)
org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1076)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:896)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.planetj.servlet.filter.compression.CompressingFilter.doFilter(CompressingFilter.java:270)
com.gamebox.filter.SiteStatusFilter.doFilterInternal(SiteStatusFilter.java:51)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
All system out/error will go to catalina.out by default. Don't use System.out.println, use a logging API and configure your logger to write to the console.
If you are using something like logback, in your application just consider it to write to console:
http://logback.qos.ch/manual/configuration.html
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
to tame spring messages, you can remove commons-logging and use slf4j to route spring into the same logging. See this article
http://www.codingpedia.org/ama/how-to-log-in-spring-with-slf4j-and-logback/
That should help improve visibility and give you your goal of getting everything into catalina.out.
Finally, I find the solution and I am very satisfy.
Only one changed, edit the TOMCAT_HOME/conf/logging.properties file then locate this line:
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler
Append , java.util.logging.ConsoleHandler to this line.
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
All exceptions will be write to catalina.out file.^_^

Logback DBAppender has null caller_filename

Using logback-1.0.13.jar and JDK 1.6u34.
I have a Java web app (WAR) with the following WEB-INF/classes/logback.xml:
<configuration debug="true" scan="true" scanPeriod="5 minutes">
<appender name="logManager-dbAppender" class="ch.qos.logback.classic.db.DBAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>NEUTRAL</onMismatch>
</filter>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>NEUTRAL</onMismatch>
</filter>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<connectionSource class="ch.qos.logback.core.db.JNDIConnectionSource">
<jndiLocation>java:comp/env/jdbc/dbLogging-local</jndiLocation>
</connectionSource>
</appender>
<root level="ALL">
<appender-ref ref="logManager-dbAppender" />
</root>
</configuration>
And the following ${TOMCAT_HOME}/conf/context.xml (global context.xml for all web apps):
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource
name="jdbc/dbLogging-local"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://my-mysql-server.example.com:3306/my_db"
username="my_user"
password="my_password"
maxActive="20"
/>
</Context>
And have the latest MySQL/JDBC driver on my runtime classpath at WEB-INF/lib/mysql-jdbc-5.1.25.jar). Additionally, because this is a global context.xml, I also have the same MySQL/JDBC driver located at ${TOMCAT_HOME}/lib.
And am getting the following stack trace:
08:54:52,905 |-ERROR in ch.qos.logback.classic.db.DBAppender[logManager-dbAppender] - problem appending event com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'caller_filename' cannot be null
at com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'caller_filename' cannot be null
at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at at com.mysql.jdbc.Util.getInstance(Util.java:386)
at at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1040)
at at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
at at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at at ch.qos.logback.classic.db.DBAppender.subAppend(DBAppender.java:105)
at at ch.qos.logback.classic.db.DBAppender.subAppend(DBAppender.java:42)
at at ch.qos.logback.core.db.DBAppenderBase.append(DBAppenderBase.java:108)
at at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:88)
at at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:48)
at at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:272)
at at ch.qos.logback.classic.Logger.callAppenders(Logger.java:259)
at at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:441)
at at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:395)
at at ch.qos.logback.classic.Logger.info(Logger.java:599)
at at com.myapp.server.DummyServlet.doGet(Unknown Source)
at at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at at java.lang.Thread.run(Thread.java:662)
Any ideas as to why I'm getting the MySQL exception? I found this similar unanswered question on Old Nabble and am wondering if it's a long-standing bug...?
It seems to be connecting to my MySQL server and inserting a NULL logging_event.caller_filename when (per the Logback DBAppender's onw DDL) NULLs are not allowed on that column.
Thanks in advance!
I've had similar problem with PostgreSQL and logback 1.0.7 with slf4j 1.6.6
Somehow it seems the caller information is not "always" passed what leads to this problem, that in turn means the concerned logging call doesn't make to database (and if there isn't debug="true" on logback configuration, you don't even know it).
As a dummy resolution, one can relax the database column constraints in the logging tables (not require "not null" in caller columns). In my case however, it turned out it matters how I construct logger instances in code: while this has caused the above failure
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Logger log = LoggerFactory.getLogger(My.class);
this worked fine (i.e. filled the caller information)
Logger log = LoggerFactory.getLogger(My.class.getName());
I can't explain it though.

Categories

Resources