You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Kamal Ahmed <KA...@webMethods.com> on 2006/03/14 19:37:12 UTC

How to Check if Appender HAS Started or not

Hi,

Here is how I am trying to log a message using log4j:

PatternLayout layout = new PatternLayout();
		wmDfa = new WmDailyFileAppender();
		wmDfa.setName("testOverlappingRollovers");
		wmDfa.setLayout(layout);
		wmDfa.setAppend(true);
		wmDfa.setFile("./log/testOverlappingRollovers.log");
		wmDfa.setDatePattern("'.'yyyy-MM-dd-HH-mm");
		logger.addAppender(wmDfa);
		wmDfa.activateOptions();
		logger.debug("overlappingRollovers---");


I create 2 files testOverlappingRollovers.log.<time and Date> , one and two
minute ahead of the current Time , outside log4j, and then I am using the
Daily Appender to write to these Files., Only one of the file, I create as
read-only, and the other one as writeable.

Now how do I know if the Appender HAS Started or not, there is nothing being
written by the appender into the log file.

Thanks,
-Kamal.



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: How to Check if Appender HAS Started or not

Posted by Curt Arnold <ca...@apache.org>.
On Mar 14, 2006, at 12:37 PM, Kamal Ahmed wrote:

> Hi,
>
> Here is how I am trying to log a message using log4j:
>
> PatternLayout layout = new PatternLayout();
> 		wmDfa = new WmDailyFileAppender();
> 		wmDfa.setName("testOverlappingRollovers");
> 		wmDfa.setLayout(layout);
> 		wmDfa.setAppend(true);
> 		wmDfa.setFile("./log/testOverlappingRollovers.log");
> 		wmDfa.setDatePattern("'.'yyyy-MM-dd-HH-mm");
> 		logger.addAppender(wmDfa);
> 		wmDfa.activateOptions();
> 		logger.debug("overlappingRollovers---");
>
>
> I create 2 files testOverlappingRollovers.log.<time and Date> , one  
> and two
> minute ahead of the current Time , outside log4j, and then I am  
> using the
> Daily Appender to write to these Files., Only one of the file, I  
> create as
> read-only, and the other one as writeable.
>
> Now how do I know if the Appender HAS Started or not, there is  
> nothing being
> written by the appender into the log file.
>
> Thanks,
> -Kamal.


In your example you are apparently using a custom appender  
WmDailyFileAppender.  It is not very helpful to ask the community to  
try to analyze a problem in a custom appender since we don't have the  
code.  That is not a request to see the code, it would be much better  
if you could experiment with the supplied appenders and ask questions  
involving them since it minimizes the effort for those who may want  
to help you and any answers may help those who encounter the issue  
later.

Anytime you ask a question, please identify the version of log4j  
used.  In particular, the log4j 1.2 and 1.3 code base are  
substantially different.

You should call layout.activateOptions() though I don't think it  
would effect the behavior on either log4j 1.2 or 1.3.

org.apache.log4j.DailyRollingFileAppender (DRFA) is not asynchronous,  
so it makes little sense to ask if it "started".

DailyRollingFileAppender does not attempt to determine if there have  
been any previously written log files.  The presence of your manually  
created log files should have no effect until a rollover.  Since you  
only show one log statement, then there can't be a rollover since  
there hasn't been a transition over a time boundary.  Reviewing the  
code, I'd expect that you'd have an entry for  
"overlappingRollovers---" in ./log/testOverlappingRollovers.log  
(assuming that you have such a directory and that you have write  
privileges).   You would only get a file with the date pattern after  
you have crossed a time boundary, you example if you added the  
following lines:

//   sleep for a minute
Thread.sleep(60000);
//   should trigger a rollover
logger.debug("Completed waiting for 60 seconds);

After that point, you should have a testOverlappingRollovers.log.2005- 
* containing "overlappingRollovers---" and a fresh  
testOverlappingRollovers.log containing "Completed waiting for 60  
seconds".

The log4j 1.2 DailyRollingFileAppender does have know problems  
dealing with locked files, but as its use is widespread, there is  
little we would want to do to change it at this time.  log4j 1.3 adds  
a new RollingFileAppender architecture which should be more robust in  
the face of locked files or unexpected file permissions.

I'm sure you could gather much more information of the behavior by  
stepping through your example in a debugger.  That is usually the  
best way to figure out what is going on if you get surprised by the  
behavior.  Sometimes the behavior is wrong and you should file a bug  
report.  Sometimes the behavior is as documented and your  
expectations were wrong.  Sometimes you are not sure and that is the  
right time to ask questions here, but you are much more likely to get  
a helpful response if you do your homework first before asking for help.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org