Aggarwal, Rajat | 8 Jul 07:41

Replace a file in DailyRollingFileAppender

Hi All,

Is there any way we can replace a file attached to a particular appender
using java code? I am using DailyRollingFileAppender for my purpose and
want to log to separate files depending upon certain configurations made
in the database. Can we dynamically change the files an appender is
writing to? If so, how?

Please help. An early response shall be highly appreciated.

Thanks and Regards,

Rajat Aggarwal

Re: Replace a file in DailyRollingFileAppender

Aggarwal, Rajat skrev  den 08-07-2008 07:44:
> Hi All,
>
>  
>
> Is there any way we can replace a file attached to a particular appender
> using java code? I am using DailyRollingFileAppender for my purpose and
> want to log to separate files depending upon certain configurations made
> in the database. Can we dynamically change the files an appender is
> writing to? If so, how?
Have you tried creating a new configuration for that particular appender 
and programatically telling log4j to load that configuration?

--
  Thorbjørn
Aggarwal, Rajat | 8 Jul 11:12

RE: Replace a file in DailyRollingFileAppender

Hi Thorbjørn

Actually, I have a created a logger instance and am adding an appender to it through my java code. So, I am not
sure if I still need to make configuration entries in log4j.properties file. If you want, I can also send
across the piece of code I have written for thee same.

Thanks and Regards,

Rajat Aggarwal

-----Original Message-----
From: Thorbjørn Ravn Andersen [mailto:thunderaxiom <at> gmail.com] 
Sent: Tuesday, July 08, 2008 1:22 PM
To: Log4J Users List
Subject: Re: Replace a file in DailyRollingFileAppender

Aggarwal, Rajat skrev  den 08-07-2008 07:44:
> Hi All,
>
>  
>
> Is there any way we can replace a file attached to a particular appender
> using java code? I am using DailyRollingFileAppender for my purpose and
> want to log to separate files depending upon certain configurations made
> in the database. Can we dynamically change the files an appender is
> writing to? If so, how?
Have you tried creating a new configuration for that particular appender 
and programatically telling log4j to load that configuration?

--
(Continue reading)

Re: Replace a file in DailyRollingFileAppender

Aggarwal, Rajat skrev  den 08-07-2008 11:12:
> Hi Thorbjørn
>
> Actually, I have a created a logger instance and am adding an appender to it through my java code. So, I am not
sure if I still need to make configuration entries in log4j.properties file. If you want, I can also send
across the piece of code I have written for thee same.
>   
You can reconfigure a logger strictly from an in-memory set of 
properties without a log4j.property file as such.

I think you should show a minimal case of what you have done, and what 
you would like to do.

--

-- 
  Thorbjørn
Eric Kolotyluk | 8 Jul 17:04

fixedWindowRollingPolicy.setFileNamePattern

One of the nice features I like in log4j 1.3 is
FixedWindowRollingPolicy#setFileNamePattern();

The log4j default rolling pattern looks like mylog.log1, mylog.log2, ...
This makes it difficult for desktops to associate the file-type with
application used for opening the log file for viewing so I like to use

FixedWindowRollingPolicy fixedWindowRollingPolicy = new
FixedWindowRollingPolicy();
fixedWindowRollingPolicy.setFileNamePattern("mylog%i.log");
fixedWindowRollingPolicy.setMaxIndex(9);
fixedWindowRollingPolicy.setMinIndex(0);

This way I only have to associate the file suffix '.log' once, with my
favorite log file editor, and not for each of '.log1' '.log2' etc.

It would be really nice to do this in log4j 1.2. Are there any plans to
add this to the 1.2 stream?

Cheers, Eric
Jacob Kjome | 8 Jul 17:28

Re: fixedWindowRollingPolicy.setFileNamePattern

See the rolling package in the Log4j "extras" companion...

http://logging.apache.org/log4j/companions/extras/index.html

Jake

On Tue, 8 Jul 2008 08:04:49 -0700
  "Eric Kolotyluk" <eric.kolotyluk <at> kodak.com> wrote:
> One of the nice features I like in log4j 1.3 is
>FixedWindowRollingPolicy#setFileNamePattern();
> 
> The log4j default rolling pattern looks like mylog.log1, mylog.log2, ...
> This makes it difficult for desktops to associate the file-type with
> application used for opening the log file for viewing so I like to use
> 
>FixedWindowRollingPolicy fixedWindowRollingPolicy = new
>FixedWindowRollingPolicy();
> fixedWindowRollingPolicy.setFileNamePattern("mylog%i.log");
> fixedWindowRollingPolicy.setMaxIndex(9);
> fixedWindowRollingPolicy.setMinIndex(0);
> 
> This way I only have to associate the file suffix '.log' once, with my
> favorite log file editor, and not for each of '.log1' '.log2' etc.
> 
> It would be really nice to do this in log4j 1.2. Are there any plans to
> add this to the 1.2 stream?
> 
> Cheers, Eric
> 
> ---------------------------------------------------------------------
(Continue reading)

Eric Kolotyluk | 8 Jul 18:13

RE: fixedWindowRollingPolicy.setFileNamePattern

Hey thanks. I can't seem to find a similar set of extras for log4net. Is
there a similar file name patter manipulator for log4net somewhere?

Cheers, Eric

-----Original Message-----
From: Jacob Kjome [mailto:hoju <at> visi.com] 
Sent: Tuesday, July 08, 2008 8:29 AM
To: Log4J Users List
Subject: Re: fixedWindowRollingPolicy.setFileNamePattern

See the rolling package in the Log4j "extras" companion...

http://logging.apache.org/log4j/companions/extras/index.html

Jake

On Tue, 8 Jul 2008 08:04:49 -0700
  "Eric Kolotyluk" <eric.kolotyluk <at> kodak.com> wrote:
> One of the nice features I like in log4j 1.3 is
>FixedWindowRollingPolicy#setFileNamePattern();
> 
> The log4j default rolling pattern looks like mylog.log1, mylog.log2,
...
> This makes it difficult for desktops to associate the file-type with
> application used for opening the log file for viewing so I like to use
> 
>FixedWindowRollingPolicy fixedWindowRollingPolicy = new
>FixedWindowRollingPolicy();
> fixedWindowRollingPolicy.setFileNamePattern("mylog%i.log");
(Continue reading)

Jacob Kjome | 9 Jul 04:03

Re: fixedWindowRollingPolicy.setFileNamePattern

Eric Kolotyluk wrote:
> Hey thanks. I can't seem to find a similar set of extras for log4net. Is
> there a similar file name patter manipulator for log4net somewhere?

I can't speak for Log4net.  I suggest pinging the Log4net lists with your questions...

http://logging.apache.org/log4net/mail-lists.html

Jake

> 
> Cheers, Eric
> 
> -----Original Message-----
> From: Jacob Kjome [mailto:hoju <at> visi.com] 
> Sent: Tuesday, July 08, 2008 8:29 AM
> To: Log4J Users List
> Subject: Re: fixedWindowRollingPolicy.setFileNamePattern
> 
> See the rolling package in the Log4j "extras" companion...
> 
> http://logging.apache.org/log4j/companions/extras/index.html
> 
> Jake
> 
> 
> On Tue, 8 Jul 2008 08:04:49 -0700
>   "Eric Kolotyluk" <eric.kolotyluk <at> kodak.com> wrote:
>> One of the nice features I like in log4j 1.3 is
>> FixedWindowRollingPolicy#setFileNamePattern();
(Continue reading)

Eric Kolotyluk | 8 Jul 19:34

RE: fixedWindowRollingPolicy.setFileNamePattern

Well, that was a good try

The extras do not come with a jar file and trying to build the
distribution fails.

I would prefer it if someone would just add this functionality to the
1.2 stream, at least that's a properly maintained release.

- Eric

-----Original Message-----
From: Jacob Kjome [mailto:hoju <at> visi.com] 
Sent: Tuesday, July 08, 2008 8:29 AM
To: Log4J Users List
Subject: Re: fixedWindowRollingPolicy.setFileNamePattern

See the rolling package in the Log4j "extras" companion...

http://logging.apache.org/log4j/companions/extras/index.html

Jake

On Tue, 8 Jul 2008 08:04:49 -0700
  "Eric Kolotyluk" <eric.kolotyluk <at> kodak.com> wrote:
> One of the nice features I like in log4j 1.3 is
>FixedWindowRollingPolicy#setFileNamePattern();
> 
> The log4j default rolling pattern looks like mylog.log1, mylog.log2,
...
> This makes it difficult for desktops to associate the file-type with
(Continue reading)

Jacob Kjome | 9 Jul 04:01

Re: fixedWindowRollingPolicy.setFileNamePattern

There is a plan to release it.  I think it's been waiting on Chainsaw 2 (or
vice-versa).  The extras are meant to work with Log4j 1.2.  Haven't tried to build
it in a quite a while.  I might have a crack at it tonight.

Jake

Eric Kolotyluk wrote:
> Well, that was a good try
> 
> The extras do not come with a jar file and trying to build the
> distribution fails.
> 
> I would prefer it if someone would just add this functionality to the
> 1.2 stream, at least that's a properly maintained release.
> 
> - Eric
> 
> -----Original Message-----
> From: Jacob Kjome [mailto:hoju <at> visi.com] 
> Sent: Tuesday, July 08, 2008 8:29 AM
> To: Log4J Users List
> Subject: Re: fixedWindowRollingPolicy.setFileNamePattern
> 
> See the rolling package in the Log4j "extras" companion...
> 
> http://logging.apache.org/log4j/companions/extras/index.html
> 
> Jake
> 
> 
(Continue reading)

Jacob Kjome | 9 Jul 07:31

Re: fixedWindowRollingPolicy.setFileNamePattern

Ok, well, I checked it out and used Maven 2.0.9 to build.  I just typed "mvn
install".  It ran all tests and built the binary in 2 minutes.  What problem did
you have?  Are you missing repositories in your ${user.home}/.m2/settings.xml?

Jake

Jacob Kjome wrote:
> There is a plan to release it.  I think it's been waiting on Chainsaw 2 (or
> vice-versa).  The extras are meant to work with Log4j 1.2.  Haven't tried to build
> it in a quite a while.  I might have a crack at it tonight.
> 
> Jake
> 
> 
> Eric Kolotyluk wrote:
>> Well, that was a good try
>>
>> The extras do not come with a jar file and trying to build the
>> distribution fails.
>>
>> I would prefer it if someone would just add this functionality to the
>> 1.2 stream, at least that's a properly maintained release.
>>
>> - Eric
>>
>> -----Original Message-----
>> From: Jacob Kjome [mailto:hoju <at> visi.com] 
>> Sent: Tuesday, July 08, 2008 8:29 AM
>> To: Log4J Users List
>> Subject: Re: fixedWindowRollingPolicy.setFileNamePattern
(Continue reading)

Eric Kolotyluk | 9 Jul 17:06

RE: fixedWindowRollingPolicy.setFileNamePattern

OK, here's what I get when I try to build the extras.

Cheers, Eric

[C:\Program Files\Apache\apache-log4j-extras-1.0]ant
Buildfile: build.xml

init:

compile:
    [javac] Compiling 83 source files to C:\Program
Files\Apache\apache-log4j-extras-1.0\target\classes
    [javac] C:\Program
Files\Apache\apache-log4j-extras-1.0\src\main\java\org\apache\log4j\Enha
ncedPatternLayout.java:20: cannot find symbol
    [javac] symbol  : class OptionConverter
    [javac] location: package org.apache.log4j.helpers
    [javac] import org.apache.log4j.helpers.OptionConverter;
    [javac]                                 ^
    [javac] C:\Program
Files\Apache\apache-log4j-extras-1.0\src\main\java\org\apache\log4j\Enha
ncedPatternLayout.java:21: cannot find symbol
    [javac] symbol  : class PatternConverter
    [javac] location: package org.apache.log4j.helpers
    [javac] import org.apache.log4j.helpers.PatternConverter;
    [javac]                                 ^
    [javac] C:\Program
Files\Apache\apache-log4j-extras-1.0\src\main\java\org\apache\log4j\Enha
ncedPatternLayout.java:23: cannot find symbol
    [javac] symbol  : class LoggingEvent
(Continue reading)

Jacob Kjome | 10 Jul 05:41

Re: fixedWindowRollingPolicy.setFileNamePattern

Hi Eric,

Eric Kolotyluk wrote:
> OK, here's what I get when I try to build the extras.
> 
> Cheers, Eric
> 
> BUILD FAILED
> C:\Program Files\Apache\apache-log4j-extras-1.0\build.xml:76: Compile
> failed; see the compiler error output for details.
> 
> Total time: 2 seconds

Stupid me.  I guess I had made some unconscious assumption that extras hadn't been
release yet.  It has and *does* come with a jar file that you can download here...

http://logging.apache.org/log4j/companions/extras/download.html

The jar file exists in the same directory as the build.xml file in the
distribution archive.  The one curious thing is that it is stored as
".\apache-log4j-extras-1.0.jar".  I'm opening it with WinRAR.  Not sure what you
see with WinZip or other archive tool?

In any case, Maven is not all that difficult to get working.  Just like Ant, you
download it, extract it to a directory, put ${MAVEN_HOME}/bin in your system path,
place the settings.xml (that I sent you privately) file in ${user.home}/.m2, and
type "mvn install".  Maven downloads all the compile-time dependencies for you.
The reason your Ant build failed is that it references dependencies located in
${user.home}/.m2/repository, which implies that you've already built using Maven
which would have downloaded those dependencies for you.  That makes that Ant build
(Continue reading)

Eric Kolotyluk | 10 Jul 15:58

RE: fixedWindowRollingPolicy.setFileNamePattern

OK, I found it now, thanks. I had to use WinZip to find it; Windows
Explorer could not see it for some reason.

I cannot understand why they put the jar file in such a subtle place - I
can see absolutely no point in that.

I'll play with it now. Thanks for the tip.

Cheers, Eric

-----Original Message-----
From: Jacob Kjome [mailto:hoju <at> visi.com] 
Sent: Wednesday, July 09, 2008 8:42 PM
To: Log4J Users List
Subject: Re: fixedWindowRollingPolicy.setFileNamePattern

Hi Eric,

Eric Kolotyluk wrote:
> OK, here's what I get when I try to build the extras.
> 
> Cheers, Eric
> 
> BUILD FAILED
> C:\Program Files\Apache\apache-log4j-extras-1.0\build.xml:76: Compile
> failed; see the compiler error output for details.
> 
> Total time: 2 seconds

Stupid me.  I guess I had made some unconscious assumption that extras
(Continue reading)


Gmane