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 "Kev." <ek...@yahoo.com> on 2006/02/21 20:10:20 UTC

Re: Use different log files inside one program

Winston Huang <weiqingh <at> mail.com> writes:

> 
> hi there,
> 
> i have a java program that behaves like a cron job which kicks off
> jobs based on certain conditions. each job is implemented by a a
> Runnable. i would like to have each job use a different log file. the
> best i can do so far is to set NDC for the Runnable or print out the
> thread name in the output. but all the logs still go to the same
> file. it's more convenient if each job can write to a different log
> file, identified by the job name for example. is there any way to do
> it? 
> 
> note that each Runnable can invoke other common classes which in turn
> use log4j inside. e.g. Runnable1 may call Util.foo, and Runnable2 may
> call Util.foo as well. the logging output from Util.foo should go to
> different log files based on the Runnable. however Util.foo uses the
> static logger that's assoicated with the Util class itself. 
> 
> any help is greatly appreciated. 
> Winston
> 


I have this problem too... Any luck figuring this out? 

This is the same issue as one program spawning multiple threads and wanting to 
direct the logging of each thread to a unique and dedicated log file.

Seem's Log4j definitely supports logging control within a specific package 
hierarchy... that is you can control packages at various levels. But what if 
you want to control at the thread (lightweight or heavyweight) level - usually 
spanning many, many disparate packages?

    Kev.



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


Re: Use different log files inside one program

Posted by James Stauffer <st...@gmail.com>.
Would the following work?  It would make a separate logger trunk per
thread name.

Logger logger = Logger.getLogger(Thread.currentThread().getName() +
"." + getClass().getName());

On 2/21/06, Kev. <ek...@yahoo.com> wrote:
> Winston Huang <weiqingh <at> mail.com> writes:
>
> >
> > hi there,
> >
> > i have a java program that behaves like a cron job which kicks off
> > jobs based on certain conditions. each job is implemented by a a
> > Runnable. i would like to have each job use a different log file. the
> > best i can do so far is to set NDC for the Runnable or print out the
> > thread name in the output. but all the logs still go to the same
> > file. it's more convenient if each job can write to a different log
> > file, identified by the job name for example. is there any way to do
> > it?
> >
> > note that each Runnable can invoke other common classes which in turn
> > use log4j inside. e.g. Runnable1 may call Util.foo, and Runnable2 may
> > call Util.foo as well. the logging output from Util.foo should go to
> > different log files based on the Runnable. however Util.foo uses the
> > static logger that's assoicated with the Util class itself.
> >
> > any help is greatly appreciated.
> > Winston
> >
>
>
> I have this problem too... Any luck figuring this out?
>
> This is the same issue as one program spawning multiple threads and wanting to
> direct the logging of each thread to a unique and dedicated log file.
>
> Seem's Log4j definitely supports logging control within a specific package
> hierarchy... that is you can control packages at various levels. But what if
> you want to control at the thread (lightweight or heavyweight) level - usually
> spanning many, many disparate packages?
>
>     Kev.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


--
James Stauffer
Are you good? Take the test at http://www.livingwaters.com/good/

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


Re: Use different log files inside one program

Posted by Jacob Kjome <ho...@visi.com>.
The best bet for both cases is to write a RepositorySelector that selects 
the LoggerRepository based on criteria you define.  The most common cases 
of repository selectors are ones based on classloader (which can cause 
classloading issues unless you are *really* careful about it) or JNDI.  I'm 
sure a few other implementations have been done as well.  See what you can 
come up with.  And, if you would, report back and let us know whether you 
succeeded.

Jake

At 07:10 PM 2/21/2006 +0000, you wrote:
 >Winston Huang <weiqingh <at> mail.com> writes:
 >
 >>
 >> hi there,
 >>
 >> i have a java program that behaves like a cron job which kicks off
 >> jobs based on certain conditions. each job is implemented by a a
 >> Runnable. i would like to have each job use a different log file. the
 >> best i can do so far is to set NDC for the Runnable or print out the
 >> thread name in the output. but all the logs still go to the same
 >> file. it's more convenient if each job can write to a different log
 >> file, identified by the job name for example. is there any way to do
 >> it?
 >>
 >> note that each Runnable can invoke other common classes which in turn
 >> use log4j inside. e.g. Runnable1 may call Util.foo, and Runnable2 may
 >> call Util.foo as well. the logging output from Util.foo should go to
 >> different log files based on the Runnable. however Util.foo uses the
 >> static logger that's assoicated with the Util class itself.
 >>
 >> any help is greatly appreciated.
 >> Winston
 >>
 >
 >
 >I have this problem too... Any luck figuring this out?
 >
 >This is the same issue as one program spawning multiple threads and 
wanting to
 >direct the logging of each thread to a unique and dedicated log file.
 >
 >Seem's Log4j definitely supports logging control within a specific package
 >hierarchy... that is you can control packages at various levels. But what if
 >you want to control at the thread (lightweight or heavyweight) level - 
usually
 >spanning many, many disparate packages?
 >
 >    Kev.
 >
 >
 >
 >---------------------------------------------------------------------
 >To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
 >For additional commands, e-mail: log4j-user-help@logging.apache.org


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