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 yesnid <ns...@pelco.com> on 2009/01/15 23:34:22 UTC

Format log message based on thread?

Hello All,

Does anyone know if there is a way to alter the formatting of log messages
from a logger based on which thread the message it is coming from?

Thank you.
-- 
View this message in context: http://www.nabble.com/Format-log-message-based-on-thread--tp21488373p21488373.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: Format log message based on thread?

Posted by Scott Deboy <sc...@gmail.com>.
One other point I want to mention:

This technique allows you to create separate log files based on thread name,
for which you could specify different layouts.

If what you're trying to do is get a single log file to contain all events
with some events formatted differently, I wouldn't use this technique.
Defining two appenders to write to the same log file can cause unexpected
behavior.

Scott

On Thu, Jan 15, 2009 at 2:49 PM, Scott Deboy <sc...@gmail.com> wrote:

> Add an ExpressionFilter to an Appender which specifies the layout you want
> for that specific thread (expressionfilter is in the extras companion, and
> will work with log4j 1.2.15):
> http://logging.apache.org/log4j/companions/extras/index.html
>
> You'll need to use two  may wa'll probably want two appenders
> An example expression for only processing events from a specific thread
> would be:
>
> THREAD == 'My thread name'
>
> You can also use the case-insensitive partial-text match operator ~= to
> match a part of the thread name, or the LIKE operator to perform regular
> expression matching.
>
> This is the same expression syntax you use in Chainsaw V2 to filter,
> colorize and search for events.  The best description of the expression
> syntax is in the Chainsaw tutorial (available from the help menu).
>
>
> On Thu, Jan 15, 2009 at 2:34 PM, yesnid <ns...@pelco.com> wrote:
>
>>
>> Hello All,
>>
>> Does anyone know if there is a way to alter the formatting of log messages
>> from a logger based on which thread the message it is coming from?
>>
>> Thank you.
>> --
>> View this message in context:
>> http://www.nabble.com/Format-log-message-based-on-thread--tp21488373p21488373.html
>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
>

Re: Format log message based on thread?

Posted by Scott Deboy <sc...@gmail.com>.
Add an ExpressionFilter to an Appender which specifies the layout you want
for that specific thread (expressionfilter is in the extras companion, and
will work with log4j 1.2.15):
http://logging.apache.org/log4j/companions/extras/index.html

You'll need to use two  may wa'll probably want two appenders
An example expression for only processing events from a specific thread
would be:

THREAD == 'My thread name'

You can also use the case-insensitive partial-text match operator ~= to
match a part of the thread name, or the LIKE operator to perform regular
expression matching.

This is the same expression syntax you use in Chainsaw V2 to filter,
colorize and search for events.  The best description of the expression
syntax is in the Chainsaw tutorial (available from the help menu).

On Thu, Jan 15, 2009 at 2:34 PM, yesnid <ns...@pelco.com> wrote:

>
> Hello All,
>
> Does anyone know if there is a way to alter the formatting of log messages
> from a logger based on which thread the message it is coming from?
>
> Thank you.
> --
> View this message in context:
> http://www.nabble.com/Format-log-message-based-on-thread--tp21488373p21488373.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>