Location of logback default file appender - java

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.

Related

spring Logback error coming when starting spring application

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.

java.lang.IllegalArgumentException: Cannot parse pattern for log back

I am getting this error in my application which is running on EMR
Here are few details about this error
It is not consistent. This error comes once in while (in two days or in a week also).
We have tried building JARs from Local /Jenkins/Maven but no luck. Still this errors appears.
Verified class in the JAR file and it is present at correct location.
It does not look like corrupted jars or class not present issue as this error is not consistent.
Here is the complete stack trace
java.lang.IllegalArgumentException: Cannot parse pattern '%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n'
at org.apache.logging.log4j.core.layout.PatternLayout$SerializerBuilder.build(PatternLayout.java:490)
at org.apache.logging.log4j.core.layout.PatternLayout.<init>(PatternLayout.java:140)
at org.apache.logging.log4j.core.layout.PatternLayout.<init>(PatternLayout.java:61)
at org.apache.logging.log4j.core.layout.PatternLayout$Builder.build(PatternLayout.java:770)
at org.apache.logging.log4j.core.config.AbstractConfiguration.setToDefault(AbstractConfiguration.java:715)
at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:47)
at org.apache.logging.log4j.core.LoggerContext.<init>(LoggerContext.java:95)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:254)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:136)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150)
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.logging.log4j.LogManager.getLogger(LogManager.java:599)
at com.company.search.tcp.rdf.jumper.driver.processclass.processMessages(processclass.java:110)
at com.company.search.ecp.tcp.jumper.driver.processclass.lambda$process$5dfe0a07$1(processclass.java:95)
at org.apache.spark.api.java.JavaRDDLike$$anonfun$foreachPartitionAsync$1.apply(JavaRDDLike.scala:741)
at org.apache.spark.api.java.JavaRDDLike$$anonfun$foreachPartitionAsync$1.apply(JavaRDDLike.scala:741)
at org.apache.spark.SparkContext$$anonfun$37.apply(SparkContext.scala:2212)
at org.apache.spark.SparkContext$$anonfun$37.apply(SparkContext.scala:2212)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
at org.apache.spark.scheduler.Task.run(Task.scala:123)
at org.apache.spark.executor.Executor$TaskRunner$$anonfun$10.apply(Executor.scala:408)
at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:414)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: zip file closed
at java.util.zip.ZipFile.ensureOpen(ZipFile.java:690)
at java.util.zip.ZipFile.access$200(ZipFile.java:61)
at java.util.zip.ZipFile$ZipEntryIterator.hasNext(ZipFile.java:512)
at java.util.zip.ZipFile$ZipEntryIterator.hasMoreElements(ZipFile.java:507)
at java.util.jar.JarFile$JarEntryIterator.hasNext(JarFile.java:264)
at java.util.jar.JarFile$JarEntryIterator.hasMoreElements(JarFile.java:273)
at org.apache.logging.log4j.core.config.plugins.util.ResolverUtil.loadImplementationsInJar(ResolverUtil.java:347)
at org.apache.logging.log4j.core.config.plugins.util.ResolverUtil.findInPackage(ResolverUtil.java:233)
at org.apache.logging.log4j.core.config.plugins.util.PluginRegistry.loadFromPackage(PluginRegistry.java:225)
at org.apache.logging.log4j.core.config.plugins.util.PluginManager.collectPlugins(PluginManager.java:136)
at org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:132)
at org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:113)
at org.apache.logging.log4j.core.layout.PatternLayout.createPatternParser(PatternLayout.java:255)
at org.apache.logging.log4j.core.layout.PatternLayout$SerializerBuilder.build(PatternLayout.java:473)
... 29 more
we don't use the pattern mentioned in the error stack trace at all .
We use below in our code
name="OFF_File_appender"
fileName="$${sys:spark.yarn.app.container.log.dir}/log4j2.log"
filePattern="$$${sys:spark.yarn.app.container.log.dir}/log4j2.log.%d{yyyy-MM-dd-HH}"
>
<PatternLayout pattern="%d{ISO8601} %-5level %c{3}[%X{currentContext}] - [log4j2] %msg%n"/>

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?

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