Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
log4j.jpg
[Thumbnail for log4j.jpg]
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
### 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
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
classes folder I mean.. "the output folder for class files"..

Its "bin" in eclipse, by default.
 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Error_log4j.jpg
[Thumbnail for Error_log4j.jpg]
 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enjoy. the LOG4J
 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
copy to ... any *dir" which is in classpath
 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic