It's not a secret anymore!*
The moose likes Other Open Source Projects and the fly likes log4j:WARN No appenders could be found for logger (LogClass) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "log4j:WARN No appenders could be found for logger (LogClass)" Watch "log4j:WARN No appenders could be found for logger (LogClass)" New topic
Author

log4j:WARN No appenders could be found for logger (LogClass)

Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
Hi,

I am trying to execute simple log4j featurs but i am getting error:

log4j:WARN No appenders could be found for logger (LogClass).
log4j:WARN Please initialize the log4j system properly.

My Log4j.properties file has code:


### direct log messages to stdout ###log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
log4j.rootLogger=debug, stdout


I am attaching my directory structure also.

My Java Class file:

import org.apache.log4j.Logger;

public class LogClass {
private static org.apache.log4j.Logger log = Logger
.getLogger(LogClass.class);

public static void main(String[] args) {

//log.trace("Trace");
log.debug("Debug");
log.info("Info");
log.warn("Warn");
log.error("Error");
log.fatal("Fatal");
}
}


Could any one tell me where i am exactly doing wrong ?

prabhat


[Thumbnail for log4j.jpg]

Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Prabhat Ranjan wrote:
### direct log messages to stdout ###log4j.appender.stdout=org.apache.log4j.ConsoleAppender


"log4j.appender.stdout=org.apache.log4j.ConsoleAppender" should be on separate line.. else it will become a comment.

Try with that and let me know..


- Chinna
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
### direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
log4j.rootLogger=debug, stdout


now it seems ok or not ?

But i am still getting error !
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Also.. its important to have log4j.properties file in classpath.

Try moving the log4j.properties in src folder.. before running make sure.. that log4j.properties is automatically copied to classes folder by the IDE.
as classes folder is by default in classpath.

Or.. Try adding the directory (in which properties file exist) to the classpath.
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

classes folder I mean.. "the output folder for class files"..

Its "bin" in eclipse, by default.
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
Classes folder i don't have but i set the output folder is bin in classpath.

also i am attaching the currect dir structure.

I moved the log4.properties in src folder.


[Thumbnail for Error_log4j.jpg]

Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
yes now working fine and i checked that in bin folder log4j.propertes are copied once i put the log4.properties in src folder.

I got the picture clear !

Thanks Chinna a lot !

Have a Good Day !

here is output:

14:34:53,564 DEBUG LogClass:10 - Debug
14:34:53,580 INFO LogClass:11 - Info
14:34:53,580 WARN LogClass:12 - Warn
14:34:53,580 ERROR LogClass:13 - Error
14:34:53,580 FATAL LogClass:14 - Fatal
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Enjoy. the LOG4J
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
Hey ,

if somegetting Error same as i got !

log4j:WARN No appenders could be found for logger (com.xyz.xyzabc.change).
log4j:WARN Please initialize the log4j system properly.

But actually she is having the log4j.properties file in config directory.

So how can she move this file to src directory..as config dir is the project requirement..

is there any another option to resolve this issue.
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

copy to ... any *dir" which is in classpath
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
ok but it is not ok in config folder..i think it is not in classpath..

ok now its working put the config folder in classpath !

thanks !
 
Consider Paul's rocket mass heater.
 
subject: log4j:WARN No appenders could be found for logger (LogClass)