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 ???
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
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
posted 15 years ago
OK, now I'm not sure at all what you're trying to accomplish, but it sounds similar to a log4j FAQ :
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
posted 15 years ago
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