Whenever I ran my webdriver script in eclipse, using java, I got following warning:
log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager).
log4j:WARN Please initialize the log4j system properly.
When I looked into Referenced Libraries I saw a 'log4j-1.2.14.jar'. This must have come along with default selenium download. What's its use??
Log4j configuration is missing. Log4j scans for configuration files log4j.xml or log4j.properties on the classpath and cannot find either.
For details, have a look at No appenders could be found for logger(log4j)? .
Example:
To setup a console appender, create file log4j.properties with the following contents and put it on the classpath:
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p %c - %m%n
Related
I'm using log4j for my final project. I tested it using single class before I used log4j in my project. That worked fine.
Then I added log4j to my project and I used it in many classes using:
final static Logger logger = Logger.getLogger(Supplier.class);
Then I got a warning:
log4j:WARN No appenders could be found for logger (classes.Supplier).
log4j:WARN Please initialize the log4j system properly.
This is my properties file:
# Root logger option
log4j.rootLogger=DEBUG, file
log4j.rootLogger=DEBUG, errorfile
# Redirect log messages to console
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.errorfile=org.apache.log4j.RollingFileAppender
# Redirect log messages to a log file, support file rolling.
log4j.appender.file.File=C:\\HardwareLog\\INFO.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.errorfile=C:\\HardwareLog\\ERROR.log
log4j.appender.errorfile.Threshhold=ERROR
log4j.appender.errorfile.MaxFileSize=5MB
log4j.appender.errorfile.MaxBackupIndex=10
log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout
log4j.appender.errorfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Do I have to create appenders for each class to use it?
Can I use one properties file in different packages ?
I found a solution. I removed root logger and added two loggers for my two packages.
log4j.logger.package1=DEBUG,FIRST
log4j.logger.package2=DEBUG,SECOND
now its working fine.
you can go for root logger that will log for the entire application.
# Root logger option
log4j.rootLogger=INFO, file
plese go through this link
https://www.mkyong.com/logging/log4j-log4j-properties-examples/
I'm trying to use log4j in my Java application (no web-app). Therefore I added the configuration file directly within my /src folder.
log4j.properties
log4j.rootLogger=DEBUG
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
My main class is in a package with a sub-namespace and within there I'm trying to log as follows:
final static Logger logger = Logger.getLogger(MainClass.class);
public static void main(String[] args) {
//BasicConfigurator.configure();
logger.warn("some warning");
}
But still I'm getting an error message and I don't know what to do. You see the commented line BasicConfigurator above. As far as I know, the log4j.properties should be read without calling that line, right?
log4j:WARN No appenders could be found for logger
(at.company.project.poi.MainClass). log4j:WARN Please initialize the
log4j system properly. log4j:WARN See
http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
According to documentation, file should be on classpath and named 'log4j2.properties'
You can also set directly the configuration by setting -Dlog4j.configurationFile="<your config filepath>"
Source: https://logging.apache.org/log4j/2.x/manual/configuration.html
I want to make to log file to my application.
I try Appach log4j for this. In Java code i says:
Logger log = Logger.getLogger(uploadfile.class);
log.debug("Start");
I create file src\log4j.properties with:
# ***** Set root logger level to DEBUG and its only appender to A.
log4j.rootLogger=DEBUG, R, A
log4j.rootLogger=INFO, A
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.MaxFileSize=100mb
log4j.appender.R.MaxBackupIndex=1000
log4j.appender.R.File=c:/uploaded_files/server.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# ***** A is set to be a ConsoleAppender.
log4j.appender.A=org.apache.log4j.ConsoleAppender
# ***** A uses PatternLayout.
log4j.appender.A.Threshold=INFO
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.logger.org.hibernate.type.BasicTypeRegistry=INFO
log4j.logger.com.opensymphony.xwork2.config.providers.XmlConfigurationProvider=INFO
I copy this there. And i get error:
13.02.2013 9:03:34 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [uploadfile] in context with path [/gis-mrsk-portlet] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager
at org.apache.log4j.Logger.getLogger(Logger.java:117)
at test.uploadfile.doPost(uploadfile.java:35)
What i doing wrong? And how to configure log4j for simple?
UPDATE
If i use this config i get log file but its empty:
Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE, LOGFILE
Set the enterprise logger priority to FATAL
log4j.logger.org.apache.axis2.enterprise=FATAL
log4j.logger.de.hunsicker.jalopy.io=FATAL
log4j.logger.httpclient.wire.header=FATAL
log4j.logger.org.apache.commons.httpclient=FATAL
CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %m%n
LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=C:/uploaded_files/LogFile.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
It seems correct.. have you set correctly the log4j Lib in your path?
The problem is not with your configuration, the problem is the non-existant support of log4j for catalina it's not as easy to get it to work together as it should be. To make log4j work with catalina follow the documentation available at http://tomcat.apache.org/tomcat-6.0-doc/logging.html#Using_Log4j.
EDIT
To summarize the link I gave:
[...] put log4j.jar and log4j.properties into WEB-INF/lib and WEB-INF/classes of your web application.
Download or build tomcat-juli.jar and tomcat-juli-adapters.jar that are available as an "extras" component for Tomcat. See Additional Components documentation for details. http://tomcat.apache.org/tomcat-6.0-doc/extras.html
After following those steps your example should already work.
/EDIT
If you want the easy part in logging I would suggest using logback which comes with native servlet support for tomcat based applications. If you want to go one step further in logging: clusterlog.net (full disclosure I own part of that company)
java.lang.NoClassDefFoundError
It looks like your Apache does not know definition of org.apache.log4j.LogManager. Have you put required jar in Apache classpath?
I am getting "Logger Not Found" error when I import org.apache.log4j.Logger. I am using JDeveloper 10.1. Do I need to configure Log4j and if so please tell me how to do that. Thanks.
You need to add the log4j jar to the classpath.
http://www.oracledistilled.com/java/adding-java-libraries-to-oracle-jdeveloper-11g-r1/
Your error sounds like you already have Log4J setup so yes, you need to configure Log4J.
Add a log4j.properties file to your classpath using the sample config below:
# Set root logger level to INFO and its only appender to ConsoleOut.
log4j.rootLogger=INFO, ConsoleOut
# ConsoleOut is set to be a ConsoleAppender.
log4j.appender.ConsoleOut=org.apache.log4j.ConsoleAppender
# ConsoleOut uses PatternLayout.
log4j.appender.ConsoleOut.layout=org.apache.log4j.PatternLayout
log4j.appender.ConsoleOut.layout.ConversionPattern=%-5p: [%d] %c{1} - %m%n
How can I disable Struts2 zillions of logs?
I constantly get logs like this:
2012-04-12 23:20:31,487 DEBUG [XWorkConverter.java:388] : Property: menuExpandedOps
I'm using struts 2.0 and standard java logging (I'm not using log4j).
The logging.properties file of the JVM is set by default to INFO, and I already have struts.devMode = false in my struts.properties file.
If you are free to use log4j, i suggest you to use that, since Log4j has the ability to set different log levels for different packages and hence using the log level OFF we can disable logging for a particular package.
In S2 most of the log messages will be from these packages
xwork2
struts2
freemarker
ognl
and a simple property file/xml file in class-path can help you to turn on or off the logging information.
and a simple property file/xml file in class-path can help you to turn on or off the logging information.
For those who want an example:
1) Put log4j.properties inside src (where your packages are):
2) Turn OFF low-level logging:
# root logger option
log4j.rootLogger=DEBUG, stdout, file
# direct log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%p: %d{yyyy-MM-dd HH:mm:ss} %F:%L] %m%n
# direct log messages to a log file, support file rolling
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/sortingmonitor.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%p: %d{yyyy-MM-dd HH:mm:ss} %F:%L] %m%n
# disable apache low level logging
log4j.category.com.opensymphony.xwork2=OFF
log4j.category.org.apache.struts2=OFF
log4j.category.freemarker.beans=OFF
log4j.category.freemarker.cache=OFF
Further reading for XML: http://deepaksrivastav.github.io/blog/2011/01/06/disable-struts-2-log-messages/