Caused by: java.io.IOException: Length 1279873876 exceeds limit: 26 - java

I am trying to implement socket appender in log4j, so that my logs get directly written to host application.
Below is my log4j config,
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" monitorInterval="5">
<Appenders>
<Socket name="socket" host="localhost" port="8085" reconnectDelayMillis="30000" protocol="TCP" immediateFlush="true">
<PatternLayout></PatternLayout>
</Socket>
<Async name="SplunkAsync">
<AppenderRef ref="socket"/>
</Async>
</Appenders>
<Loggers>
<Root level="warn">
<AppenderRef ref="SplunkAsync"/>
</Root>
<Logger name="org.mule.module.http.internal.HttpMessageLogger" level="debug" additivity="false">
<AppenderRef ref="SplunkAsync"/>
</Logger>
</Loggers>
</Configuration>
I have also tried sending messages to this localhost 8085 port from java program, which works perfectly fine.
But with log4j appender, I get below exception,
Caused by: java.io.IOException: Length 1279873876 exceeds limit: 26
ERROR 2018-10-10 19:55:52,897 [[tcplistner].connector.tcp.mule.default.receiver.02] org.mule.exception.DefaultSystemExceptionStrategy: Caught exception in Exception Strategy: An error occurred while verifying your connection. You may not be using a consistent protocol on your TCP transport. Please read the documentation for the TCP transport, paying particular attention to the protocol parameter.
java.io.IOException: An error occurred while verifying your connection. You may not be using a consistent protocol on your TCP transport. Please read the documentation for the TCP transport, paying particular attention to the protocol parameter.
at org.mule.transport.tcp.protocols.SafeProtocol.helpUser(SafeProtocol.java:110) ~[mule-transport-tcp-3.8.5.jar:3.8.5]
at org.mule.transport.tcp.protocols.SafeProtocol.assertSiblingSafe(SafeProtocol.java:83) ~[mule-transport-tcp-3.8.5.jar:3.8.5]
at org.mule.transport.tcp.protocols.SafeProtocol.read(SafeProtocol.java:37) ~[mule-transport-tcp-3.8.5.jar:3.8.5]
at org.mule.transport.tcp.TcpMessageReceiver$TcpWorker.getNextMessage(TcpMessageReceiver.java:367) ~[mule-transport-tcp-3.8.5.jar:3.8.5]
at org.mule.transport.AbstractReceiverResourceWorker.doRun(AbstractReceiverResourceWorker.java:41) ~[mule-core-3.8.5.jar:3.8.5]
at org.mule.transport.AbstractReceiverWorker.run(AbstractReceiverWorker.java:66) ~[mule-core-3.8.5.jar:3.8.5]
at org.mule.transport.TrackingWorkManager$TrackeableWork.run(TrackingWorkManager.java:267) ~[mule-core-3.8.5.jar:3.8.5]
at org.mule.work.WorkerContext.run(WorkerContext.java:301) ~[mule-core-3.8.5.jar:3.8.5]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_144]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_144]
Caused by: java.io.IOException: Length 1279873876 exceeds limit: 26
at org.mule.transport.tcp.protocols.LengthProtocol.read(LengthProtocol.java:71) ~[mule-transport-tcp-3.8.5.jar:3.8.5]
at org.mule.transport.tcp.protocols.SafeProtocol.assertSiblingSafe(SafeProtocol.java:79) ~[mule-transport-tcp-3.8.5.jar:3.8.5]

Looking at the class name org.mule.module.http.internal.HttpMessageLogger you see an .internal. package. That is a strong hint that you should not be using that package at all.
What is happening is that you are using an internal Mule implementation class as a Log4j2 custom appended for Splunk. That is not the intended usage for that class in any case.
What you should be doing is looking at Splunk documentation and following the steps there.

Related

Logback configuration error detected: no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]

I have a Springboot application with Logback. This war is running in a Liberty webserver in a docker container
Versions:
Springboot 2.5.3
Logback 1.2.3
I am seeing a weird behavior where if I run this container on a Mac or Redhat, the application starts up fine and logs as expected.
However, when the same docker container is run in Ubuntu, I am seeing the following error from Logback's Joran interpreter :
...
08:07:53,308 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework] to WARN
08:07:53,308 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.hibernate] to WARN
08:07:53,308 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [springfox] to WARN
08:07:53,313 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter#88:32 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
08:07:53,313 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter#89:51 - no applicable action for [root], current ElementPath is [[configuration][springProfile][root]]
08:07:53,314 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter#90:73 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
08:07:53,314 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
08:07:53,314 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator#5b3de2a2 - Registering current configuration as safe fallback point
[err] Logging system failed to initialize using configuration from '/logback-spring.xml'
[err] java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter#88:32 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter#89:51 - no applicable action for [root], current ElementPath is [[configuration][springProfile][root]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter#90:73 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
[err] at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:179)
[err] at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
[err] at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)
[err] at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:132)
[err] at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:316)
[err] at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:282)
[err] at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:240)
[err] at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)
[err] at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
[err] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
[err] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
[err] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
[err] at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
[err] at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
[err] at org.springframework.boot.SpringApplicationRunListeners$$Lambda$71/0x000000006c31f840.accept(Unknown Source)
[err] at java.util.ArrayList.forEach(ArrayList.java:1270)
[err] at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
[err] at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
[err] at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
[err] at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:374)
[err] at org.springframework.boot.SpringApplication.run(SpringApplication.java:332)
[err] at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:175)
[err] at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:155)
[err] at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:97)
[err] at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174)
[err] at com.ibm.ws.webcontainer.webapp.WebApp.initializeServletContainerInitializers(WebApp.java:2550)
[err] at [internal classes]
[err] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1160)
[err] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[err] at java.lang.Thread.run(Thread.java:822)
Here is my logback configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="console-json"
class="ch.qos.logback.core.ConsoleAppender">
<encoder name="LoggingEventCompositeJsonEncoder"
class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp/>
<version/>
<message/>
<loggerName>
<shortenedLoggerNameLength>20
</shortenedLoggerNameLength>
</loggerName>
<threadName/>
<logLevel/>
<logLevelValue/>
<callerData>
<fieldName>caller</fieldName>
<classFieldName>class</classFieldName>
<methodFieldName>method</methodFieldName>
<fileFieldName>file</fileFieldName>
<lineFieldName>line</lineFieldName>
</callerData>
<stackTrace>
<throwableConverter
class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
<maxDepthPerThrowable>100</maxDepthPerThrowable>
<maxLength>10000</maxLength>
<shortenedClassNameLength>30
</shortenedClassNameLength>
<rootCauseFirst>true</rootCauseFirst>
<inlineHash>true</inlineHash>
</throwableConverter>
</stackTrace>
<stackHash/>
<jsonMessage/>
<mdc/>
<contextMap/>
<tags/>
<logstashMarkers/>
<arguments>
<includeNonStructuredArguments>true
</includeNonStructuredArguments>
<nonStructuredArgumentsFieldPrefix>prefix
</nonStructuredArgumentsFieldPrefix>
</arguments>
</providers>
</encoder>
</appender>
<logger name="org.springframework" level="WARN"/>
<logger name="org.hibernate" level="WARN"/>
<logger name="springfox" level="WARN"/>
<springProfile name="prod">
<root level="${logback_root_level:-INFO}">
<appender-ref ref="${logback_root_appender:-console-json}"/>
</root>
</springProfile>
<springProfile name="minimal">
<root level="${logback_root_level:-WARN}">
<appender-ref ref="${logback_root_appender:-console-json}"/>
</root>
</springProfile>
</configuration>
Any help is appreciated!
Check if your logback file is a spring logback file like "logback-spring.xml".
Had the exact same issue fixed it by changing the file name.

Log4J does not want to create logfile

In my project I use Log4j to process all logging. The config I use:
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d - %-5p %-10c - %m%n"/>
</Console>
<File name="file" fileName="logs/TAF_${sys:current_date}.log">
<PatternLayout>
<Pattern>%d{yyyy-mm-dd_HH:mm:ss.SSS} - %-5p %-10c - %m%n</Pattern>
</PatternLayout>
</File>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="file" level="DEBUG"/>
<AppenderRef ref="STDOUT" level="DEBUG"/>
</Root>
</Loggers>
The error I get:
2018-11-19 16:12:59,531 main ERROR FileManager (logs\TAF_${sys:current_date}.log) java.io.IOException: De syntaxis van de bestandsnaam, mapnaam of volumenaam is onjuist java.io.IOException: De syntaxis van de bestandsnaam, mapnaam of volumenaam is onjuist
at java.base/java.io.WinNTFileSystem.canonicalize0(Native Method)
at java.base/java.io.WinNTFileSystem.canonicalize(WinNTFileSystem.java:432)
at java.base/java.io.File.getCanonicalPath(File.java:618)
at java.base/java.io.File.getCanonicalFile(File.java:643)
at org.apache.logging.log4j.core.util.FileUtils.makeParentDirs(FileUtils.java:142)
at org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory.createManager(FileManager.java:418)
at org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory.createManager(FileManager.java:406)
at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:113)
at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:114)
at org.apache.logging.log4j.core.appender.FileManager.getFileManager(FileManager.java:180)
at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:95)
at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:51)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:123)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at nl.*****.Apl.<clinit>(Apl.java:9)
2018-11-19 16:12:59,536 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.FileAppender for element File: java.lang.IllegalStateException: ManagerFactory [org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory#1ffaf86] unable to create manager for [logs\TAF_${sys:current_date}.log] with data [org.apache.logging.log4j.core.appender.FileManager$FactoryData#6574a52c] java.lang.IllegalStateException: ManagerFactory [org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory#1ffaf86] unable to create manager for [logs\TAF_${sys:current_date}.log] with data [org.apache.logging.log4j.core.appender.FileManager$FactoryData#6574a52c]
at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:115)
at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:114)
at org.apache.logging.log4j.core.appender.FileManager.getFileManager(FileManager.java:180)
at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:95)
at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:51)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:123)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at nl.*****.Apl.<clinit>(Apl.java:9)
2018-11-19 16:12:59,541 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.FileAppender for element File: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.FileAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.FileAppender
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:235)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:135)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at nl.******.Apl.<clinit>(Apl.java:9)
2018-11-19 16:12:59,543 main ERROR Null object returned for File in Appenders.
2018-11-19 16:12:59,550 main ERROR Unable to locate appender "file" for logger config "root"
The first error is in dutch, which translates to: "The filename, directory name, or volume label syntax is incorrect".
This Log4J config file is used under an Ubuntu environment and works perfectly. Now I have added a Win10 machine to the pool, but I receive this error.
What am I doing wrong?
I tried to make the path absolute, "c:/Project/logs/TAF_${sys:current_date}.log", but it did not solve the problem. Every user has read/write access to the logs directory.
Other stuff I tried:
Log4j logfile error FileNotFoundException
#edit:
For what I can see, it looks like log4j is trying to create a file named "TAF_${sys:current_date}.log". That ofcourse doesn't work, because { and } are not valid for filenames. When the "_${sys:current_date}" is removed, I am able to create the log file. How am I able to use the expression again, to add the current date/time?
#edit2:Found the answer here. I needed to set the system property "current_date" in the code.

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