aspose file tools*
The moose likes Other Open Source Projects and the fly likes log4j config file setup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "log4j config file setup" Watch "log4j config file setup" New topic
Author

log4j config file setup

dmhorse
Greenhorn

Joined: Dec 28, 2003
Posts: 3
We know 3 appender for logging to the file.
FILEAPPENDER
ROLLINGFILEAPPENDER
DAILYROLLINGFILEAPPENDER
Suppose we choose FILEAPPENDER,but it would append the log message of the log file.We want the log4j override the log file at every time when the program running.
How can I setup?
Does the log4j contain the override parameter to setup in the config file?
I doesn't find that.
Any idea apprecation.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Look again at the javadoc for the Log4j API. The constructor for FileAppender and its two subclasses RollingFileAppender and DailyRollingFileAppender can take a boolean parameter which tells them to append to the file. Set that parameter to false and the file will be truncated before being logged to. You can also call setAppend(false) to do the same trick.
I would guess that there is a property Append (or append) which you can set to false.
[ December 28, 2003: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
And "dmhorse dmhorse" I just noticed: please take a look at JavaRanch's Naming Policy and change your displayed name accordingly. You can change it here: Edit your profile.
Thanks,
-Barry
dmhorse
Greenhorn

Joined: Dec 28, 2003
Posts: 3
Thx
I defind 2 appender as the following setting.
One for HTML log,other for console log.
When executing the "TEST.Log4jTEST",it would log the message to the html file.
When executing the "TEST.Log4jOtherTEST",it earse the html file.
Do any way prevent them?
I don't want the TEST.Log4jOtherTEST affect the TEST.Log4jTEST's log.
Although I have separate them in 2 loggers in the setting file.
dmhorse
Greenhorn

Joined: Dec 28, 2003
Posts: 3
I have 3 or more application in the same package.
All of them using the same logger(read the same log4j config file).
The application may be running at the same time.
I want to seperate them to different log according to the main class.
Any way to do that?
Write a great many catergory in the config file?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
"dmhorse" thanks for changing your displayed name. But it's still not correct. If dm are your initials and the horse is your last/family name it should be "d.m. horse" to conform to our naming policy. Please fix it.
Returning to your problem, I would like to help, but do not have the time to write a complete test program for your problem. If you have a short example program that demonstrates what you want to do I will try to run it and see if I can help.
[ January 01, 2004: Message edited by: Barry Gaunt ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
The following may be something like what you want to do:

Here's a test program:

Here's some console output showing what log4j is doing.


The above is based upon information found in the
complete manual for log4j essential reading if you really need to learn log4j.
 
 
subject: log4j config file setup