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 Chien Wei Tan <Ch...@calytrix.com> on 2001/08/15 03:00:04 UTC
Assigning Layouts to Priorities
Hi,
Would anyone know if it is possible to define different layouts (including
conversion patterns) for different priorities, (either through the
configuration file, or in the actual log4j classes), given a specific
category.
eg. MyApp is a dummy class thats gets an instance of Category, and uses
DEBUG, INFO, WARN, ERROR, and FATAL. Is is possible to log messages in such
a way that:
DEBUG uses PatternLayout, ConversionPattern=%10p (%F:%L) - %m%n
INFO uses SimpleLayout
WARN uses PatternLayout, ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
ERROR uses PatternLayout, ConversionPattern=%-5r %8p [%t] %c - %m%n
FATAL uses PatternLayout, ConversionPattern=%-5r [%t] %c - %m%n
Any help would be greatly appreciated,
chienwei
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: newbie: How to distinguish log outputs from different
instances of the same class?
Posted by Robert Leftwich <di...@ix.net.au>.
At 04:08 PM 15/08/2001, Chien Wei Tan wrote:
>Hi,
>
>How would I use log4j to distinguish the log messages coming from different
>instances of the same class?
>
>Eg. MyClass m1 = new MyClass(); // output log messages to MyLog.log
> MyClass m2 = new MyClass(); // output log messages to MyLog.log, and
>MyOtherLog.log
> MyClass m3 = new MyClass(); // output log messages to MyOtherLog.log
> MyClass m4 = new MyClass(); // output log messages to MyOtherLog.log,
>and MyLog.log
>
>
>if the above classes output log messages to MyLog.log and MyOtherLog.log,
>how can i differentiate from the log messages, which instance of MyClass is
>the source?????
>
>In addition, 1) if m1, m2, m3, m4 were all running from the same location,
> 2) and what if they were distributed and running from
> different
>locations?
What feature of the class distinguishes each instance (the default being
the address in memory).?
You could use an NDC to log that see the examples for usage of NDC's - in
particular SortAlgo.java) or prefix every log output with 'this', e.g.
logger.debug(this+"My message").
Does that help?
Robert
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
RE: Assigning Layouts to Priorities
Posted by Robert Leftwich <di...@ix.net.au>.
At 04:11 PM 15/08/2001, Chien Wei Tan wrote:
>hi rob,
>
>thanks... i understand how to log different priorities to different
>appenders... but i m actually after logging different layouts to different
>priorities... any ideas?
That's what Ceki is suggesting, something along the lines of (note this is
untested - I am sure someone will correct me if I am wrong!) :
log4j.appender.DEBUG_APPENDER=org.apache.log4j.ConsoleAppender
log4j.appender.INFO_APPENDER=org.apache.log4j.ConsoleAppender
log4j.appender.WARN_APPENDER=org.apache.log4j.ConsoleAppender
...
# DEBUG_APPENDER uses PatternLayout.
log4j.appender.DEBUG_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.DEBUG_APPENDER.layout.ConversionPattern=%-4r [%t] %-5p %c %x
- %m%n
# INFO_APPENDER uses SimpleLayout.
log4j.appender.INFO_APPENDER.layout=org.apache.log4j.SimpleLayout
...
# assign categories/priorities combinations to different appenders
log4j.category.yours=DEBUG, DEBUG_APPENDER
log4j.additivity.DEBUG=false
log4j.category.yours=WARN, WARN_APPENDER
log4j.additivity.WARN=false
...
You should end up with output to the console in different formats depending
on the priority.
HTH
Robert
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
newbie: How to distinguish log outputs from different instances of the same class?
Posted by Chien Wei Tan <Ch...@calytrix.com>.
Hi,
How would I use log4j to distinguish the log messages coming from different
instances of the same class?
Eg. MyClass m1 = new MyClass(); // output log messages to MyLog.log
MyClass m2 = new MyClass(); // output log messages to MyLog.log, and
MyOtherLog.log
MyClass m3 = new MyClass(); // output log messages to MyOtherLog.log
MyClass m4 = new MyClass(); // output log messages to MyOtherLog.log,
and MyLog.log
if the above classes output log messages to MyLog.log and MyOtherLog.log,
how can i differentiate from the log messages, which instance of MyClass is
the source?????
In addition, 1) if m1, m2, m3, m4 were all running from the same location,
2) and what if they were distributed and running from different
locations?
any help would be great,
chienwei
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
RE: Assigning Layouts to Priorities
Posted by Keith Schomburg <ks...@cisco.com>.
Chien Wei,
One other thing to mention that I observed when doing
this is that if you use an AsyncAppender the performance
is greatly improved. I went from ~375 milliseconds to
~85 milliseconds when I switched to use an AsyncAppender.
This was with a simple test to log 100 events to the
console.
Keith
> -----Original Message-----
> From: Keith Schomburg [mailto:kschombu@cisco.com]
> Sent: Wednesday, August 15, 2001 10:55 AM
> To: LOG4J Users Mailing List
> Subject: RE: Assigning Layouts to Priorities
>
>
> Chien Wei,
>
> I was working on trying to do the very thing you were.
> Attached is a xml configuration file that I used to
> do what your asking. You will need to use the
> DOMConfigurator class to do this.
>
> Hope this helps.
>
> Keith
>
> > -----Original Message-----
> > From: Chien Wei Tan [mailto:Chienwei.Tan@calytrix.com]
> > Sent: Wednesday, August 15, 2001 2:11 AM
> > To: LOG4J Users Mailing List; digital@ix.net.au
> > Subject: RE: Assigning Layouts to Priorities
> >
> >
> >
> > hi rob,
> >
> > thanks... i understand how to log different priorities to different
> > appenders... but i m actually after logging different layouts
> to different
> > priorities... any ideas?
> >
> > cheers,
> > chienwei
> >
> > -----Original Message-----
> > From: Robert Leftwich [mailto:digital@ix.net.au]
> > Sent: Wednesday, 15 August 2001 9:19 AM
> > To: LOG4J Users Mailing List
> > Subject: Re: Assigning Layouts to Priorities
> >
> >
> > At 11:00 AM 15/08/2001, Chien Wei Tan wrote:
> >
> >
> > >Hi,
> > >
> > >Would anyone know if it is possible to define different layouts
> > (including
> > >conversion patterns) for different priorities, (either through the
> > >configuration file, or in the actual log4j classes), given a specific
> > >category.
> > >
> > >eg. MyApp is a dummy class thats gets an instance of Category, and uses
> > >DEBUG, INFO, WARN, ERROR, and FATAL. Is is possible to log
> > messages in such
> > >a way that:
> > >
> > > DEBUG uses PatternLayout, ConversionPattern=%10p
> (%F:%L) - %m%n
> > > INFO uses SimpleLayout
> > > WARN uses PatternLayout, ConversionPattern=%-4r [%t]
> %-5p %c %x
> > > - %m%n
> > > ERROR uses PatternLayout, ConversionPattern=%-5r %8p [%t] %c -
> > %m%n
> > > FATAL uses PatternLayout, ConversionPattern=%-5r [%t]
> %c - %m%n
> > >
> > >
> > >Any help would be greatly appreciated,
> > >chienwei
> >
> > This from Ceki yesterday:
> >
> > >What you can do is to log different priorities to different
> > appenders. You
> > >can then attach a different layout (e.g. a PatternLayout) to each
> > >appender. Hope this helps, Ceki
> >
> >
> > Robert
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: log4j-user-help@jakarta.apache.org
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: log4j-user-help@jakarta.apache.org
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
RE: Assigning Layouts to Priorities
Posted by Chien Wei Tan <Ch...@calytrix.com>.
thanks... i m gonna try it out :)
-----Original Message-----
From: Keith Schomburg [mailto:kschombu@cisco.com]
Sent: Wednesday, 15 August 2001 10:55 PM
To: LOG4J Users Mailing List
Subject: RE: Assigning Layouts to Priorities
Chien Wei,
I was working on trying to do the very thing you were.
Attached is a xml configuration file that I used to
do what your asking. You will need to use the
DOMConfigurator class to do this.
Hope this helps.
Keith
> -----Original Message-----
> From: Chien Wei Tan [mailto:Chienwei.Tan@calytrix.com]
> Sent: Wednesday, August 15, 2001 2:11 AM
> To: LOG4J Users Mailing List; digital@ix.net.au
> Subject: RE: Assigning Layouts to Priorities
>
>
>
> hi rob,
>
> thanks... i understand how to log different priorities to different
> appenders... but i m actually after logging different layouts to different
> priorities... any ideas?
>
> cheers,
> chienwei
>
> -----Original Message-----
> From: Robert Leftwich [mailto:digital@ix.net.au]
> Sent: Wednesday, 15 August 2001 9:19 AM
> To: LOG4J Users Mailing List
> Subject: Re: Assigning Layouts to Priorities
>
>
> At 11:00 AM 15/08/2001, Chien Wei Tan wrote:
>
>
> >Hi,
> >
> >Would anyone know if it is possible to define different layouts
> (including
> >conversion patterns) for different priorities, (either through the
> >configuration file, or in the actual log4j classes), given a specific
> >category.
> >
> >eg. MyApp is a dummy class thats gets an instance of Category, and uses
> >DEBUG, INFO, WARN, ERROR, and FATAL. Is is possible to log
> messages in such
> >a way that:
> >
> > DEBUG uses PatternLayout, ConversionPattern=%10p (%F:%L) - %m%n
> > INFO uses SimpleLayout
> > WARN uses PatternLayout, ConversionPattern=%-4r [%t] %-5p %c %x
> > - %m%n
> > ERROR uses PatternLayout, ConversionPattern=%-5r %8p [%t] %c -
> %m%n
> > FATAL uses PatternLayout, ConversionPattern=%-5r [%t] %c - %m%n
> >
> >
> >Any help would be greatly appreciated,
> >chienwei
>
> This from Ceki yesterday:
>
> >What you can do is to log different priorities to different
> appenders. You
> >can then attach a different layout (e.g. a PatternLayout) to each
> >appender. Hope this helps, Ceki
>
>
> Robert
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
RE: Assigning Layouts to Priorities
Posted by Keith Schomburg <ks...@cisco.com>.
Chien Wei,
I was working on trying to do the very thing you were.
Attached is a xml configuration file that I used to
do what your asking. You will need to use the
DOMConfigurator class to do this.
Hope this helps.
Keith
> -----Original Message-----
> From: Chien Wei Tan [mailto:Chienwei.Tan@calytrix.com]
> Sent: Wednesday, August 15, 2001 2:11 AM
> To: LOG4J Users Mailing List; digital@ix.net.au
> Subject: RE: Assigning Layouts to Priorities
>
>
>
> hi rob,
>
> thanks... i understand how to log different priorities to different
> appenders... but i m actually after logging different layouts to different
> priorities... any ideas?
>
> cheers,
> chienwei
>
> -----Original Message-----
> From: Robert Leftwich [mailto:digital@ix.net.au]
> Sent: Wednesday, 15 August 2001 9:19 AM
> To: LOG4J Users Mailing List
> Subject: Re: Assigning Layouts to Priorities
>
>
> At 11:00 AM 15/08/2001, Chien Wei Tan wrote:
>
>
> >Hi,
> >
> >Would anyone know if it is possible to define different layouts
> (including
> >conversion patterns) for different priorities, (either through the
> >configuration file, or in the actual log4j classes), given a specific
> >category.
> >
> >eg. MyApp is a dummy class thats gets an instance of Category, and uses
> >DEBUG, INFO, WARN, ERROR, and FATAL. Is is possible to log
> messages in such
> >a way that:
> >
> > DEBUG uses PatternLayout, ConversionPattern=%10p (%F:%L) - %m%n
> > INFO uses SimpleLayout
> > WARN uses PatternLayout, ConversionPattern=%-4r [%t] %-5p %c %x
> > - %m%n
> > ERROR uses PatternLayout, ConversionPattern=%-5r %8p [%t] %c -
> %m%n
> > FATAL uses PatternLayout, ConversionPattern=%-5r [%t] %c - %m%n
> >
> >
> >Any help would be greatly appreciated,
> >chienwei
>
> This from Ceki yesterday:
>
> >What you can do is to log different priorities to different
> appenders. You
> >can then attach a different layout (e.g. a PatternLayout) to each
> >appender. Hope this helps, Ceki
>
>
> Robert
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>
RE: Assigning Layouts to Priorities
Posted by Chien Wei Tan <Ch...@calytrix.com>.
hi rob,
thanks... i understand how to log different priorities to different
appenders... but i m actually after logging different layouts to different
priorities... any ideas?
cheers,
chienwei
-----Original Message-----
From: Robert Leftwich [mailto:digital@ix.net.au]
Sent: Wednesday, 15 August 2001 9:19 AM
To: LOG4J Users Mailing List
Subject: Re: Assigning Layouts to Priorities
At 11:00 AM 15/08/2001, Chien Wei Tan wrote:
>Hi,
>
>Would anyone know if it is possible to define different layouts (including
>conversion patterns) for different priorities, (either through the
>configuration file, or in the actual log4j classes), given a specific
>category.
>
>eg. MyApp is a dummy class thats gets an instance of Category, and uses
>DEBUG, INFO, WARN, ERROR, and FATAL. Is is possible to log messages in such
>a way that:
>
> DEBUG uses PatternLayout, ConversionPattern=%10p (%F:%L) - %m%n
> INFO uses SimpleLayout
> WARN uses PatternLayout, ConversionPattern=%-4r [%t] %-5p %c %x
> - %m%n
> ERROR uses PatternLayout, ConversionPattern=%-5r %8p [%t] %c -
%m%n
> FATAL uses PatternLayout, ConversionPattern=%-5r [%t] %c - %m%n
>
>
>Any help would be greatly appreciated,
>chienwei
This from Ceki yesterday:
>What you can do is to log different priorities to different appenders. You
>can then attach a different layout (e.g. a PatternLayout) to each
>appender. Hope this helps, Ceki
Robert
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: Assigning Layouts to Priorities
Posted by Robert Leftwich <di...@ix.net.au>.
At 11:00 AM 15/08/2001, Chien Wei Tan wrote:
>Hi,
>
>Would anyone know if it is possible to define different layouts (including
>conversion patterns) for different priorities, (either through the
>configuration file, or in the actual log4j classes), given a specific
>category.
>
>eg. MyApp is a dummy class thats gets an instance of Category, and uses
>DEBUG, INFO, WARN, ERROR, and FATAL. Is is possible to log messages in such
>a way that:
>
> DEBUG uses PatternLayout, ConversionPattern=%10p (%F:%L) - %m%n
> INFO uses SimpleLayout
> WARN uses PatternLayout, ConversionPattern=%-4r [%t] %-5p %c %x
> - %m%n
> ERROR uses PatternLayout, ConversionPattern=%-5r %8p [%t] %c - %m%n
> FATAL uses PatternLayout, ConversionPattern=%-5r [%t] %c - %m%n
>
>
>Any help would be greatly appreciated,
>chienwei
This from Ceki yesterday:
>What you can do is to log different priorities to different appenders. You
>can then attach a different layout (e.g. a PatternLayout) to each
>appender. Hope this helps, Ceki
Robert
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org