Log4J problem  
Author Message
bilaribilari





PostPosted: 2004-7-7 13:40:00 Top

java-programmer, Log4J problem Hi everyone,

Consider the following piece of code:

Logger mylogger = Logger.getLogger(Log4JFileDeletionTest.class);

public Log4JFileDeletionTest() throws Exception
{
FileAppender fapp = new FileAppender(new
XMLLayout(),"/tmp/Log4JFileDeletionTest.log",true);
mylogger.setLevel(Level.DEBUG);
mylogger.addAppender(fapp);

mylogger.info("This is a test log");

Thread.sleep(7000);


mylogger.info("This is after deleting the file");
}

If during the Sleep(), I delete the log file, then none of the
subsequent log statements re-create the file. It remains deleted, no
exceptions get thrown and all the logs are lost.

Is there any solution to this, other than modifying the log4J code ?

Thanks in advance.
 
Phillip Mills





PostPosted: 2004-7-7 20:10:00 Top

java-programmer >> Log4J problem In article <email***@***.com>,
email***@***.com (FET) wrote:

> Is there any solution to this, other than modifying the log4J code ?

How about either subclassing or wrapping Logger with a class of your own
and having yourlogger.info() do whatever you want?

--
Phillip Mills
Multi-platform software development
(416) 224-0714
 
Marcus Eaton





PostPosted: 2004-7-7 22:56:00 Top

java-programmer >> Log4J problem FET wrote:

> If during the Sleep(), I delete the log file, then none of the
> subsequent log statements re-create the file. It remains deleted, no
> exceptions get thrown and all the logs are lost.
>
> Is there any solution to this, other than modifying the log4J code ?

I tried to run your test (on a windows machine), but was unable to
delete the file. Anyhow, looking at the log4j code, the file output
stream is created when you initialise the appender... therefore, i don't
think it would implicitly try to re-create it per info/debug message.

Phillip Mills wrote:

> How about either subclassing or wrapping Logger with a class of your
> own and having yourlogger.info() do whatever you want?

Sublassing the Logger will not do it, but you could create a sub-class
of the FileAppender, which re-initialises the stream/file per event, but
that creates too much over-head.

It might be a silly question, but why do you need this functionality
anyway? Do you expect your users to constantly be deleting your log
files? :)

Marcus

 
 
Manfred Rosenboom





PostPosted: 2004-7-7 23:39:00 Top

java-programmer >> Log4J problem On a Unix like system the file will be deleted in the directory entry, but
the file's entries in the file system will be still allocated until you close
the last file descriptor to this file. I.e.: Log4j will still write to the
file but you can neither see nor access the file anymore.

Why you don't use a rolling file appender wiht Log4j ?

Best,
Manfred
 
 
bilaribilari





PostPosted: 2004-7-8 12:01:00 Top

java-programmer >> Log4J problem Even in a RollingFileAppender, if the first file is deleted,
everything held in the buffer is lost when the max size is reached. It
is only when the new buffer is created, that a new file gets created.

Anyway, actually the reason for posting this problem is that I was
thinking about all possible test cases for the application and this is
also a possibility, though remote.

Thanks a lot all you guys for your prompt response!

Manfred Rosenboom <email***@***.com> wrote in message news:<cch5f3$1fs$email***@***.com>...
> On a Unix like system the file will be deleted in the directory entry, but
> the file's entries in the file system will be still allocated until you close
> the last file descriptor to this file. I.e.: Log4j will still write to the
> file but you can neither see nor access the file anymore.
>
> Why you don't use a rolling file appender wiht Log4j ?
>
> Best,
> Manfred
 
 
Sandy





PostPosted: 2005-10-12 16:06:00 Top

java-programmer >> Log4J problem Hi

I have a wrapper around log4j, i m using an object of this wrapper for
logging purpose. I want a log message with FileName and the line number so i
have used %F and %l

but when i run the program it gives "?" in place of FileName and in place of
line number it prints (Unknown Source)

Can somebody tell me what could be the problem

Thanks


 
 
Sandy





PostPosted: 2005-10-12 16:08:00 Top

java-programmer >> Log4J problem Hi

I have a wrapper around log4j, i m using an object of this wrapper for
logging purpose. I want a log message with FileName and the line number so i
have used %F and %l

but when i run the program it gives "?" in place of FileName and in place of
line number it prints (Unknown Source)

Can somebody tell me what could be the problem

Thanks