IMPOSSIBLE to do this with LOG4J

Discussion in 'Java' started by ProgDario, Apr 29, 2005.

  1. ProgDario

    ProgDario Guest

    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
     
    ProgDario, Apr 29, 2005
    #1
    1. Advertising

  2. ProgDario wrote:
    > ... 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.
     
    Thomas Schodt, Apr 29, 2005
    #2
    1. Advertising

  3. 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!

    ProgDario wrote:

    > 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
     
    Abhijat Vatsyayan, Apr 29, 2005
    #3
  4. ProgDario

    ProgDario Guest

    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
     
    ProgDario, May 2, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandra Stehman

    eclipse, junit, log4j, & finding log4j.xml

    Alexandra Stehman, Jan 19, 2004, in forum: Java
    Replies:
    0
    Views:
    5,778
    Alexandra Stehman
    Jan 19, 2004
  2. Alex Hunsley
    Replies:
    2
    Views:
    12,941
    =?ISO-8859-15?Q?Fr=E9d=E9ric_G=E9din?=
    May 28, 2004
  3. Rodolfo
    Replies:
    0
    Views:
    955
    Rodolfo
    Jul 12, 2004
  4. joes
    Replies:
    1
    Views:
    2,169
  5. Replies:
    5
    Views:
    261
    Michele Dondi
    Jun 30, 2006
Loading...

Share This Page