This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes log4j use best way Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "log4j use best way " Watch "log4j use best way " New topic
Author

log4j use best way

shankha bhattacharya
Greenhorn

Joined: Apr 20, 2007
Posts: 12
How can I use log4j in the best way in my program?

I configure all logging properties in the properties file.

/*******************************************


#For File Append of the logs
log4j.rootCategory=DEBUG, rfware
log4j.appender.rfware=org.apache.log4j.RollingFileAppender
log4j.appender.rfware.File=c:/temp/aiicommunicator.log
log4j.appender.rfware.Threshold=DEBUG
log4j.appender.rfware.Append=false
log4j.appender.rfware.MaxFileSize=1000KB
log4j.appender.rfware.MaxBackupIndex=2
log4j.appender.rfware.layout=org.apache.log4j.PatternLayout
log4j.appender.rfware.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

/*********************************************************************

But I want to load this properties during the start up of my application for logging in my java all java classes.

can you provide some code guide line how can I achieve it ?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

If you put that into a file named log4j.properties and make sure that the properties file is in a directory that's in the classpath when you run your application, then Log4J will automatically find it and you don't have to do anything special to initialise Log4J in your application.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
shankha bhattacharya
Greenhorn

Joined: Apr 20, 2007
Posts: 12
If I am not use the name log4j.properties then how can I use it to my application?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Promoting to the intermediate forum.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
Doesn't this belong in "Other opensource"?

Anyway, take a look at the PropertyConfigurator. If you call configure(file) or configureAndWatch(file) before the first log statement, it will use the configuration in the given file.
jianfeng ding
Greenhorn

Joined: Sep 06, 2007
Posts: 2
how about use: PropertyConfigurator.configure(".\\src\\log4j.properties") first init the log4j?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

"west west", please check your private messages. You can see them by clicking My Profile.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: log4j use best way