IMPOSSIBLE to do this with LOG4J

P

ProgDario

HI,

my customer asked me to log the application events with a rotation file
appenderm, a new file is created when the previous file reachs a
certain size.

The subtle thing is that when the maximum number of file is reached,
the old one must me deleted and a new file has to be created.

Morover, every file name must contain the date time in its path.

So if the file size limit is 4 and a new file is created, the first
file is erased, and the new file name created contains the date/time
detail:

[FileName_29-04-05_12:12:12.log] -> erased
FileName_29-04-05_12:17:05.log
FileName_29-04-05_12:22:45.log
FileName_29-04-05_12:35:45.log
FileName_29-04-05_12:50:01.log -> new file created


Any hint??

Thanks!!


:)ario
 
T

Thomas Schodt

ProgDario said:
... log the application events with a rotation file
appenderm, a new file is created when the previous file reachs a
certain size.

Which matches RollingFileAppender.
The subtle thing is that when the maximum number of file is reached,
the old one must me deleted and a new file has to be created.

Still matches RollingFileAppender.
Morover, every file name must contain the date time in its path.

If the current file need not have this,
this matches DailyRollingFileAppender.
So if the file size limit is 4 and a new file is created, the first
file is erased, and the new file name created contains the date/time
detail:

[FileName_29-04-05_12:12:12.log] -> erased
FileName_29-04-05_12:17:05.log
FileName_29-04-05_12:22:45.log
FileName_29-04-05_12:35:45.log
FileName_29-04-05_12:50:01.log -> new file created

Apache is open source.

Look at the two [RollingFileAppender, DailyRollingFileAppender].
Maybe you can figure out how to implement a combination of the two.

Have a look at existing 3rd party extensions
<http://logging.apache.org/log4j/docs/download.html>
maybe someone already did it.
 
A

Abhijat Vatsyayan

A quick fix will be to subclass from RollingFileAppender and override
method "public void rollOver() ". You may have to embed your naming
conventions in the implementation or you could get some information from
configuration. Get the date format, file name format
(filename-<date>-<count>.log ) etc. from log4j configuration. Then
implement naming conventions that use this information. It really is up to
you!
 
P

ProgDario

Thanks,

I think I'll try to subclass from RollingFileAppender, but what do you
mean for
Get the date format from log4j configuration

?

Thanks again!!

Dario
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top