Showing posts with label log4j.properties. Show all posts
Showing posts with label log4j.properties. Show all posts

25 March 2011

log4j.properties log to file example

log4j.appender.save2file=org.apache.log4j.FileAppender
log4j.appender.save2file.layout=org.apache.log4j.PatternLayout
log4j.appender.save2file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.save2file.File=c:\\newsEditor.log


in line  log4j.rootLogger=debug , save2file
debug you can replace to any log4j levels
 save2file is name of appender which you can change to any.

log4j.properties log to console example

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{ABSOLUTE} %5p %c{1}:%L - %m%n

log4j.rootLogger=debug , stdout

in line  log4j.rootLogger=debug , stdout
debug you can replace to any log4j levels
 stdout is name of appender which you can change to any.

how to add log4j.properties to classpath in Eclipse (For java aplication)?

Fancy log4j ?
 Good,because it is cool stuff....
 However ...but when you get started, then everything looks simply and go smoothly until you trying to run application , then  ... you see.

log4j:WARN No appenders could be found for logger (org.my.amazing.application).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

 No good, then question is Set I everything correctly ?

Below you have receipe how to setup log4j correctly to be DAMN sure, that it will work.

1) add log4j.jar to lib (or any place where you store your libraries

2) and add log4j.properties to src folder in Java Resources

and btw. make sure that  configure log4j.properties correctly.

how to add log4j.properties to classpath in Netbeans (For java aplication)?

Fancy log4j ?
 Good,because it is cool stuff....
 However ...but when you get started, then everything looks simply and go smoothly until you trying to run application , then  ... you see.

log4j:WARN No appenders could be found for logger (org.my.amazing.application).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

 No good, then question is Set I everything correctly ?

Below you have receipe how to setup log4j correctly to be DAMN sure, that it will work.

1) add log4j.jar to lib (or any place where you store your libraries

2) and add log4j.properties to <default package> in source Packages.

and btw. make sure that  configure log4j.properties correctly.