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
Related
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
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?
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/
I am using log4j for my application - there I need to see all log messages, so I defined
# General configuration
log4j.rootLogger = ALL, ConsoleAppender
# Appender configuration
log4j.appender.ConsoleAppender = org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.ConsoleAppender.layout.ConversionPattern = %5p (%c) %m%n
But, after I started using Apache's HTTPClient library (which is awesome btw), my console got clouded up by its logging - everything was logged and I am not able to see the log output from my own application any more.
So how can I tell the HTTPClient library that it should only log WARN messages, while my own application still logs on ALL levels?
I create my application logger using
Logger logger = Logger.getLogger(MyClass.class);
PropertyConfigurator.configure("log4j.properties");
It's quite simple. Just add the below line.
log4j.logger.org.apache.commons.httpclient=WARN
Similarly, you can configure levels for any package com.foo or class com.foo.Bar by appending it to the prefix log4j.logger as follows:
log4j.logger.com.foo=MYLEVEL
log4j.logger.com.foo.Bar=DEBUG
While running the application i do not able to set the jndi.properties and log4j.properties
Actually i have to se the following properities but I do not know where to write these code in a file or somewhere else. If in file what will be the file extension and file name and where to keep it in application.
jndi.properties:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099
log4j.properties:
# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
You can set the default JBoss JNDI properties in jboss\server\default\conf\jndi.properties file.
I can't understand what you want to do or which Jboss version you use. But for the log4j options in Jboss 4.2.3 go to:
jboss\server\default\conf\jboss-log4j.xml