log4j not logging today, worked fine two days ago - log4j

This has been asked multiple times but I have not been able to figure out what is wrong from the past questions that have been answered.
my log4j logging was working fine on Dec 31. Today, Jan 2, my first day back to work nothing is being logged. The data that should have been logged is showing up on the console but not in the log file. My log4j.properties is below. Nothing in it was changed between the last time logging was working and today.
My application is servlet based and I see no errors in either catalina or localhost logs.
I have no idea what could have happened. Does anyone have any ideas?
I just realized that I did an SVN update on the project before starting today. I might have gotten newer version of some jar file. Can a jar 'collision' cause log4j to stop logging?
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
log4j.logger.AppLogFile=DEBUG,AppLogFile
log4j.appender.AppLogFile.File=../logs/dbconnect.log
log4j.appender.AppLogFile=org.apache.log4j.RollingFileAppender
log4j.appender.AppLogFile.layout=org.apache.log4j.PatternLayout
log4j.appender.AppLogFile.layout.ConversionPattern=DBCONNECT %-22d{dd/MMM/yyyy HH:mm:ss} - %m%n
# manage logging for packages
log4j.category.org.springframework=ERROR
log4j.category.org.hibernate=ERROR
log4j.category.com.mchange.v2=ERROR

I'm answering my own question here. After four hours of searching I found the answer.
The problem was a third party jar that came down from SubVersion when I did an update. This jar was added yesterday by a developer working on a different part of the application.
Log4j looks for 'log4j.xml' before it looks for 'log4j.properties'. The third party jar contained a log4j.xml so that one was loaded and my log4j.properties was ignored.
This was pretty easy to find once I added the log4j debug command.
So, here is how to do it if you find yourself in this situation.
Stop Tomcat
In %CATALINA_HOME%/bin create a file called setenv.bat. Add these lines to the file:
REM Use this file to set either or both JAVA_OPTS, CATALINA_OPTS
REM Don't change startup.bat
set JAVA_OPTS=-Dlog4j.debug
Save and Restart Tomcat
Log4j will now log useful information, including what config file it is using, to the console.
When Tomcat starts the app Log4j logs the search for a config file. Here are two excerpts; the first showing what was happening to me the second showing what is normal behavior for my situation.
Case 1: Log4j is looking in the right place, /WEB-APPS/emscribe/WEB-INF/classes, but for log4j.xml not log4j.properties
log4j: Trying to find [log4j.xml] using context classloader WebappClassLoader
context: /emscribe
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader#1f7fd168
log4j: Using URL [jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/apache-tomcat-7.0.26/webapps/emscribe/WEB-INF/lib/dynamicreports-examples-3.0.0.jar!/log4j.xml] for automatic log4j configuration.
So, here Log4j found log4j.xml in the recently added third party jar and looked no further.
Case 2: With the third party jar removed log4j found the correct config file:
log4j: Trying to find [log4j.xml] using context classloader WebappClassLoader
context: /emscribe
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader#8b10bd5
log4j: Trying to find [log4j.xml] using WebappClassLoader
context: /emscribe
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader#8b10bd5class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader WebappClassLoader
context: /emscribe
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader#8b10bd5
.
log4j: Using URL [file:/C:/Program%20Files/Apache%20Software%20Foundation/apache-tomcat-7.0.26/webapps/emscribe/WEB-INF/classes/log4j.properties] for automaticlog4j configuration.
log4j: Reading configuration from URL file:/C:/Program%20Files/Apache%20Software%20Foundation/apache-tomcat-7.0.26/webapps/emscribe/WEB-INF/classes/log4j.properties
I eventually replaced log4j.properties with an equivalent log4j.xml, replaced the third-party jar and my log4j.xml was found before the one in the jar.

I had a different issue. I imported a project where log4j.properties was there with everything configured. There was a log file name too in the properties file, but it did not write a log file during running the project in eclipse.
Putting -Dlog4j.debug in the VM arguments in run configuration helped me to analyze, it printed all the configuration log4j doing during initialization of itself, found what I had to change in my properties file.

Related

log4j 2.0.2 on slf4j 1.7.7 can't find log4j.xml on startup?

I'm trying to get slf4j 1.7.7 to use log4j 2.0.2 as its implementation. I think I have all the necessary JARs in my WAR and the log4j.xml just gets dropped into the classes directory, but when my webapp starts up, it can't locate the log4j.xml. When I crack open the WAR, I can see it in the WEB-INF/classes, so it should be on the classpath. What am I missing?
meta-inf/manifest.mf
index.html
...
WEB-INF/web.xml
WEB-INF/classes/log4j.xml
...
WEB-INF/lib/log4j-api-2.0.2.jar
...
WEB-INF/lib/slf4j-api-1.7.7.jar
...
WEB-INF/lib/log4j-core-2.0.2.jar
WEB-INF/lib/log4j-slf4j-impl-2.0.2.jar
...
Jetty has this in its stderrout.log file, recording its disappointment...
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Well that is subtle. log4j-core-2.0.2 isn't looking for log4j.xml, its looking for log4j2.xml. The FAQ page http://logging.apache.org/log4j/2.x/faq.html has, in bold, "By default, Log4j looks for a configuration file named log4j2.xml (not log4j.xml) in the classpath." Renaming my file to log4j2.xml gets it found. Now I've got to make it correct.
2014-10-24 10:34:53,542 ERROR Unknown object "property" of type org.apache.logging.log4j.core.config.Property is ignored.
2014-10-24 10:34:53,545 ERROR Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.
2014-10-24 10:34:53,546 ERROR Unknown object "root" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.

Configure log4j.properties in Intellij

I have problem configure log4j properties.
I used to use code to configure logger.
But, now I am getting the no appenders could be found WARN from groovyx.net.http.RESTClient which I can't change the code. The WARN is below:
log4j:WARN No appenders could be found for logger (groovyx.net.http.RESTClient).
log4j:WARN Please initialize the log4j system properly.
So I tried to use the log4j.properties file by default to setup the appenders. But, I don't know where I should put the log4j.properties file. I add the -Dlog4j.debug as JVM option and run the test. I am getting the below information:
log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader#a6eb38a.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader#a6eb38a class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader#a6eb38a.
log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader#a6eb38a class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [null].
I am using IntelliJ and running a Spock test.
Any answer will be appreciate. Thank you.
Your log4j config file should be placed in source root.
In IDEA it may be resource folder.
Look at: Where should I put the log4j.properties file?
For Groovy it all the same.
In intellij, you can assign a path to the configuration file as follows:
Open the edit configuration dialog box
Click on the logs tab
Click on the plus sign to add a path to your properties/xml file. You can add an alias for this configuration.
Apply.
To check if your log4j config file has been loaded, you can add the VM Option under run/edit configuration as -Dlog4j.debug. Using this argument log4j will log into the console steps relating to the process of loading the file.

logger.IsDebugEnabled() always return false

i am new to log4j and i have the following log4j.properties file in my java application
i am working on this in websphere 6.1
log4j.properties file
log4j.rootLogger=info, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.package_name=debug
However this is working if i am using only one project as part of my application.If there are multiple projects and i want to use logging facility,logger.isDebugEnabled() always return false.. can anybody suggest a solution for this?
Thanks in advance
Websphere use a classloader for default for each EAR. If you have several Web modules or EJB modules and several files for log4j, only one is loaded by the classloader.
See A Powerful, Easy-to-Use Logging System for configure log4j with several projects in a EAR.
# Set root logger level to INFO and appender to STDOUT.
log4j.rootLogger=INFO, STDOUT
#------------------------------------STDOUT-----------------------------------#
# STDOUT is set to be a ConsoleAppender.
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
# STDOUT uses PatternLayout.
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%d %-5p (%c.java:%L).%M - %m%n
log4j.appender.STDOUT.Encoding=UTF-8
#-----------------------------------------------------------------------------#
# Specify the logging level for loggers from other libraries
log4j.logger.org.apache.commons.beanutils.BeanUtils=DEBUG
log4j.logger.org.apache.struts.action=DEBUG
log4j.logger.org.apache.struts.tiles=DEBUG
log4j.logger.org.apache.struts.util.ModuleUtils=DEBUG
log4j.logger.org.apache.struts.util.RequestUtils=DEBUG
log4j.logger.org.apache.struts.util.PropertyMessageResources=ERROR
log4j.logger.com.ibm._jsp=DEBUG
May you are missing the log4j.logger. prefix for each particular package.
See more of log4j in http://logging.apache.org/log4j/1.2/manual.html

WARN No appenders could be found for logger (org.apache.accumulo.start.classloader.AccumuloClassLoader)

Does anyone know how to get rid of the following warnings when starting accumulo:
log4j:WARN No appenders could be found for logger (org.apache.accumulo.start.classloader.AccumuloClassLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
I am running accumulo 1.4.0 hadoop 0.20.2 and zookeeper 3.3.3. I understand this warning happens because the class can not find the log4j.properties file and yes I have read http://logging.apache.org/log4j/1.2/manual.html. My log4j.properties file has the following lines copied from an accumulo 1.4.3 log4j file (I dont have the option to upgrade my system to 1.4.3):
# default logging properties:
# by default, log everything at INFO or higher to the console
log4j.rootLogger=INFO,A1
# hide Jetty junk
log4j.logger.org.mortbay.log=WARN,A1
# hide "Got brand-new compresssor" messages
log4j.logger.org.apache.hadoop.io.compress=WARN,A1
# hide junk from TestRandomDeletes
log4j.logger.org.apache.accumulo.server.test.TestRandomDeletes=WARN,A1
# hide almost everything from zookeeper
log4j.logger.org.apache.zookeeper=ERROR,A1
# hide AUDIT messages in the shell, alternatively you could send them to a different logger
log4j.logger.org.apache.accumulo.core.util.shell.Shell.audit=WARN,A1
# Send most things to the console
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} [%-8c{2}] %-5p: %m%n
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
I have put this log4j file everyone. In the accumulo/bin folder, in the accumulo/conf folder, in the accumulo/lib folder but can not get rid of this warning (I know it has to go on the accumulo class path but dont know where that is). I also can't pass a log4j.configuration option to the java compiler because the accmulo executable comes pre-compiled (I just run it).
Thanks in advance for the help.
EDIT: Below is the result of an "accumulo classpath" command on my system:
[admin-cloud#NODE1 bin]$ echo $ACCUMULO_HOME
/accumulo/accumulo-1.4.0
[admin-cloud#NODE1 bin]$ accumulo classpath
Accumulo List of classpath items are:
file:/accumulo/accumulo-1.4.0/lib/commons-collections-3.2.jar
file:/accumulo/accumulo-1.4.0/lib/commons-configuration-1.5.jar
file:/accumulo/accumulo-1.4.0/lib/log4j-1.2.16.jar
file:/accumulo/accumulo-1.4.0/lib/libthrift-0.6.1.jar
file:/accumulo/accumulo-1.4.0/lib/commons-jci-core-1.0.jar
file:/accumulo/accumulo-1.4.0/lib/commons-lang-2.4.jar
file:/accumulo/accumulo-1.4.0/lib/commons-logging-api-1.0.4.jar
file:/accumulo/accumulo-1.4.0/lib/accumulo-server-1.4.0.jar
file:/accumulo/accumulo-1.4.0/lib/accumulo-start-1.4.0.jar
file:/accumulo/accumulo-1.4.0/lib/commons-jci-fam-1.0.jar
file:/accumulo/accumulo-1.4.0/lib/jline-0.9.94.jar
file:/accumulo/accumulo-1.4.0/lib/examples-simple-1.4.0.jar
file:/accumulo/accumulo-1.4.0/lib/cloudtrace-1.4.0.jar
file:/accumulo/accumulo-1.4.0/lib/commons-logging-1.0.4.jar
file:/accumulo/accumulo-1.4.0/lib/accumulo-core-1.4.0.jar
file:/accumulo/accumulo-1.4.0/lib/commons-io-1.4.jar
file:/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.jar
file:/hadoop/hadoop-0.20.2/conf/
file:/hadoop/hadoop-0.20.2/hadoop-0.20.2-examples.jar
file:/hadoop/hadoop-0.20.2/hadoop-0.20.2-test.jar
file:/hadoop/hadoop-0.20.2/hadoop-0.20.2-tools.jar
file:/hadoop/hadoop-0.20.2/hadoop-0.20.2-ant.jar
file:/hadoop/hadoop-0.20.2/hadoop-0.20.2-core.jar
file:/hadoop/hadoop-0.20.2/lib/log4j-1.2.15.jar
file:/hadoop/hadoop-0.20.2/lib/jasper-runtime-5.5.12.jar
file:/hadoop/hadoop-0.20.2/lib/slf4j-log4j12-1.4.3.jar
file:/hadoop/hadoop-0.20.2/lib/commons-httpclient-3.0.1.jar
file:/hadoop/hadoop-0.20.2/lib/mockito-all-1.8.0.jar
file:/hadoop/hadoop-0.20.2/lib/jetty-6.1.14.jar
file:/hadoop/hadoop-0.20.2/lib/oro-2.0.8.jar
file:/hadoop/hadoop-0.20.2/lib/servlet-api-2.5-6.1.14.jar
file:/hadoop/hadoop-0.20.2/lib/junit-3.8.1.jar
file:/hadoop/hadoop-0.20.2/lib/commons-logging-api-1.0.4.jar
file:/hadoop/hadoop-0.20.2/lib/commons-codec-1.3.jar
file:/hadoop/hadoop-0.20.2/lib/core-3.1.1.jar
file:/hadoop/hadoop-0.20.2/lib/jets3t-0.6.1.jar
file:/hadoop/hadoop-0.20.2/lib/hsqldb-1.8.0.10.jar
file:/hadoop/hadoop-0.20.2/lib/slf4j-api-1.4.3.jar
file:/hadoop/hadoop-0.20.2/lib/jasper-compiler-5.5.12.jar
file:/hadoop/hadoop-0.20.2/lib/jetty-util-6.1.14.jar
file:/hadoop/hadoop-0.20.2/lib/commons-net-1.4.1.jar
file:/hadoop/hadoop-0.20.2/lib/commons-logging-1.0.4.jar
file:/hadoop/hadoop-0.20.2/lib/commons-cli-1.2.jar
file:/hadoop/hadoop-0.20.2/lib/xmlenc-0.52.jar
file:/hadoop/hadoop-0.20.2/lib/kfs-0.2.2.jar
file:/hadoop/hadoop-0.20.2/lib/commons-el-1.0.jar
Line 84 of bin/accumulo in Apache Accumulo 1.4.0 sets the variable XML_FILES to $ACCUMULO_HOME/conf and then adds XML_FILES to the CLASSPATH variable which is later passed to the java command.
https://svn.apache.org/repos/asf/accumulo/tags/1.4.0/bin/accumulo
It sounds you have a misconfiguration of ACCUMULO_HOME either through your shell environment or in $ACCUMULO_HOME/conf/accumulo-env.sh.
I was troubleshooting an installation someone else set up that was having the same problem. My solution to this problem was simply that there actually was no log4j.properties in the conf directory! So I just copied up one of the log4j.properties from the conf/examples directory, restarted and everything worked like it should!

How to configure log4j and Selenium Grid?

When I launch a Grid hub using Ant, the logging is all by default on the console. I would like to know if there is a way wherein I can alter the build.xml file of Selenium Grid and include a log4j logger into it. I understand that I can specify a log file to Ant itself using the -logfile option. But this would cause the log file to be overwritten everytime the grid is launched. I want to ensure that the log files are automatically renamed after a threshold is reached for better maintenance. Any help and if possible some examples on how to do it would be greatly appreciated (I am new to using log4j which is why I am asking for some sample for this specific need).
You need to specify the location of the Log4j archive as well as its configuration file when starting up Selenium. In the following example, I've updated the classpath to load the log4j.hub.properties configuration file located in the /etc/selenium directory and the log4j.jar located in the /usr/lib/selenium directory. I've also setup some additional log files:
java -classpath /etc/selenium:/usr/lib/selenium/log4j.jar:/usr/lib/selenium/selenium-server-standalone.jar -Dlog4j.configuration=log4j.hub.properties org.openqa.grid.selenium.GridLauncher -role hub -log /var/log/selenium/hub.debug.log > /var/log/selenium/hub.output.log 2> /var/log/selenium/hub.error.log &
Then you can have something like the following to achieve what you are looking for:
log4j.rootLogger=ALL, file
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=/var/log/selenium/hub.log
log4j.appender.file.Append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} <%p> <%t> %m%n
You might want to look at this page for more information about how Selenium logging is working.

Resources