This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

log4j DailyRollingFileAppender

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I try to log information with two different DailyRollingFileAppender in a same file :

#logging for trace-> rolling file
log4j.logger.ICOM_SMS_FILE=INFO,ICOM_SMS_FILE
log4j.appender.ICOM_SMS_FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ICOM_SMS_FILE.DatePattern=yyyy-MM-dd
log4j.appender.ICOM_SMS_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ICOM_SMS_FILE.File=C:\\logs\\log\\app-info.stat
log4j.appender.ICOM_SMS_FILE.layout.ConversionPattern=%-18d{dd/MM/yy HH:mm:ss}: %m%n


#logging for debugging ->rolling file
log4j.logger.debug_mode=DEBUG, DEBUG_MODE
log4j.appender.DEBUG_MODE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DEBUG_MODE.DatePattern=yyyy-MM-dd
log4j.appender.DEBUG_MODE.layout=org.apache.log4j.PatternLayout
log4j.appender.DEBUG_MODE.File=C:\\logs\\log\\app-info.stat
log4j.appender.DEBUG_MODE.layout.ConversionPattern=%-18d{dd/MM/yy HH:mm:ss}: %m%n

So after the period (one day) the first logger create the archive file and then log to the new file
But when i log with the second logger it also try to create the archive file and so delete the one created by the first logger ....
Is it a normal behavior ???
Can't we have 2 DailyRollingFileAppender on the same file ???

Thanks
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Can't we have 2 DailyRollingFileAppender on the same file ???



That would not be recommended, because of the behavior you describe. If you want them to log to the same file, then why not use the same appender? If I'm not mistaken there is no difference between the two appenders other than the name.

# two loggers, use same appender
log4j.logger.ICOM_SMS_FILE=INFO, DAILY_FILE
log4j.logger.debug_mode=DEBUG, DAILY_FILE

#logging - rolling file
log4j.appender.DAILY_FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DAILY_FILE.DatePattern=yyyy-MM-dd
log4j.appender.DAILY_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.DAILY_FILE.File=C:\\logs\\log\\app-info.stat
log4j.appender.DAILY_FILE.layout.ConversionPattern=%-18d{dd/MM/yy HH:mm:ss}: %m%n
 
faucher frederic
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response

the conf file was just a example...
The logger is the same but then in our application according to the logger we create differents messages (not very clear i think)

the "synchronisation" between different Daily logger on a same file is just made by name comparison (my english is really bad) and so the information is not shared between all the logger....
Have to search for a solution
thanks for your help
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, now I'm not sure at all what you're trying to accomplish, but it sounds similar to a log4j FAQ :

3.3 How do I get multiple process to log to the same file?
You may have each process log to a SocketAppender. The receiving SocketServer (or SimpleSocketServer) can receive all the events and send them to a single log file.
 
faucher frederic
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
watch for your solution with 2 logger using the same appender : i think it does not resolve the problem
logger 1 try to log something -> detect rollover is needed create archive file and log to the new current one
then logger 2 try to log something -> try to do a rollover beccause he has no idea of what logger 1 does or not
-> in this case delete the archive file created by the logger 1 and do his job (basic case)
-> or if we tell him not to delete already existing archive file then the next try to log from logger 1 will overwrite what logger 2 has log....

not very clear but pretty strange behavior
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An easier solution that may not suit your needs might be to just log to two different files. Or the socket appender would be a workaround to get the output into a single file.

I suppose there are at least a few different things that could be going wrong. If you want to continue the discussion please provide some details.

What kind of application are you logging from? Web app? EJBs? Regular java app? What do the two loggers, ICOM_SMS_FILE and DEBUG_MODE represent?

I found a similar problem someone was having with log4j losing log files using RollingFileAppender. Kind of long thread, their problem was when they redeployed the application on tomcat the vm was keeping a handle to the log file. So it couldn't rename the file. Doesn't sound like the same problem, but it's a helpful mailing list.

I do not think it is just that two loggers use the same appender, that SEEMS like it should be supported. It seems like it would be because the two loggers are not using the same instance of the appender.

I can see why the file would get deleted if that is the case because just before it tries to rename the file it checks to see if the target file name exists and if it does it deletes it.

Snippet from DailyRollingFileAppender.java rollover method:


You could try turning log4j debug on (log4j.debug=true in properties or -Dlog4j.debug on command-line), you may see an error. log4j seems to print out an error once, not over and over.
[ April 08, 2005: Message edited by: Carol Enderlin ]
 
Squanch that. And squanch this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic