I am using log4j-1.2.16.jar with Tomcat 6. The log4j config is handled with a log4j.xml file in the WEB-INF\classes directory. I turned log4j debug on. When it process a level element for a logger I get output like:
log4j: Level value for root is [WARNING].
log4j: root level set to DEBUG
Therefore all debug messages are logged when not wanted.
Any ideas why this could be happening?
Level should be WARN not WARNING.
(It would be nice if log4j.debug gave an invalid level message.)
Related
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.
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.
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
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!
I've just deployed my first app to CloudFoundry, and I use log4j. When I deploy the app to a local tomcat server, the logs print just fine as all is well. But, when I use the "vmc logs " command to get the logs from the instance on CloudFoundry, I only get the tomcat initialization logs and this message:
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Anything further that I've printed with log4j is not visible. System.out.println messages show up, but no log4j messages.
I've placed my log4j.properties file in my WEB-INF directory, and here are its contents:
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=INFO, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p %-35c{1} %m%n
log4j.logger.org.springframework=WARN
My logger object is created as would probably be expected in my classes:
private static Logger log = Logger.getLogger(MyClass.class);
Any suggestions as to what configuration I'm missing to have my log4j logs show up in my CloudFoundry logs? Or am I retrieving them incorrectly?
Is Log4j set to output to STDOUT by default? 'vmc logs' will only return the contents of STDOUT, STDERR and the staging log files.
If you app is logging to a different file then use 'vmc file' to view the content.