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 Ramakrishna Menon <ra...@oracle.com> on 2004/02/29 22:17:48 UTC

ThreadLocalAppender for log4j?

Folks
My first question to the list - and I admit I am not a log4j pro:-) - I did
look around quite a bit
before posting...

Basically, the requirement is very simple:

We are using J2EE infrastructure (jsp, middle tier code accessing data in
the
database) to render UI. During the UI rendering the code in middle tier
accesses
the database. Currently, log4j is being used to log the middle tier code. I
want
to intercept the log4j messages transaprently and store them in a
ThreadLocal
variable in the servlet. This would be helpful in dumping the UI
instrumentation
code in the middle tier to the URL being rendered based on a URL flag (
e.g. you can change a url
http://myapp/mypage
to http://myapp/mypage$debug=1

to dump all the middle tier UI rendering logic in the URL. I want this to
happen
without changig the current log4j instrumentation code. This means I need to
intercept and channel the log4j messages to a ThreadLocal variable ..Hence
I thought of writing a ThreadLocalAppender (I am almost done with it.)
I basically extended from the AppenderSkeleton for my ThreadLocalAppender
and overrode the activateOptions, checkEntryConditions() and subAppend
methods.
My question is:
1. Is this kind of Appender available already?
2. Is my thinking correct in general about creating a separate Appender
class to channel
   the log4j messages transparently.
3. Does it make sense to submit the code for this Appender so that it can be
used correctly?
4. Any other comments?

Thanx a bunch!

Best Regards,
Menon:)
-------------------------------------------------------------
Ramakrishna M. Menon (A Rafi Fan - http://www.mohdrafi.com )
MBA, Berkeley
Oracle Corp.-> (650) 506-2343
http://websites.oraclecorp.com/websites/pub/oracleperformance/
-------------------------------------------------------------

----- Original Message ----- 
From: "Scott Deboy" <sd...@comotivsystems.com>
To: "Log4J Users List" <lo...@logging.apache.org>
Sent: Sunday, February 29, 2004 12:39 PM
Subject: RE: pattern and chainsaw


I agree, log files stored in a non-XML format should be viewable in Chainsaw
v2.

I contributed a Receiver which provides Log4J (and Chainsaw v2) the ability
to process events stored in a logfile written using an arbitrary format
(PatternLayout).

In order to use this receiver, follow the instructions in the 'installation'
section of the Chainsaw v2 page and use the XML configuration provided below

Here's a link to the Chainsaw v2 page:
http://logging.apache.org/log4j/docs/chainsaw.html

See the javadoc of the new Receiver for an explanation of the available
keywords used by the the 'logFormat' param:
http://cvs.apache.org/viewcvs.cgi/logging-log4j/src/java/org/apache/log4j/varia/LogFilePatternReceiver.java?rev=1.1&view=auto

Here is the example XML configuration, which can load events written to disk
using this PatternLayout format: %r [%t] %-5p %c %x - %m%n

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="true">
   <plugin name="LogFileReceiver"
class="org.apache.log4j.varia.LogFilePatternReceiver">
      <param name="timestampFormat" value="yyyy-MM-d HH:mm:ss,SSS"/>
      <param name="logFormat" value="RELATIVETIME [THREAD] LEVEL LOGGER * -
MESSAGE"/>
      <param name="fileName" value="c:/logs/A4.log"/>
   </plugin>
   <root>
      <level value="debug"/>
   </root>
</log4j:configuration>

If anyone has questions, let me know

Scott


-----Original Message-----
From: Jean Charles Jabouille [mailto:JEAN-CHARLES.JABOUILLE@BULL.NET]
Sent: Fri 2/27/2004 1:16 AM
To: Log4J Users List
Cc:
Subject: Re: pattern and chainsaw
i'm ok with you, but i don't want a XML file. I want a .log file. I want
to use the chainsaw v1. And when i open chainsaw and submit my log file,
it's found "0 events".
I think that's a pattern problem. So i'dlike to know the standard pattern
for Chainsaw v1.

Thanks for your reply

Scott Deboy wrote:

> Chainsaw can display log files which were formatted using XMLLayout.
>
> The version of Chainsaw in CVS - see
> http://logging.apache.org/log4j/docs/chainsaw.html - can also display
> jdk1.4 util.logging files if they were formatted using XMLFormatter.
>
> Replace the layout specified in your file appender with this:
>
>         <layout class="org.apache.log4j.xml.XMLLayout"/>
>
> Scott
>
> -----Original Message-----
> From: Jean Charles Jabouille [mailto:JEAN-CHARLES.JABOUILLE@BULL.NET]
> Sent: Thursday, February 26, 2004 4:21 AM
> To: log4j-user@logging.apache.org
> Subject: pattern and chainsaw
>
> Hi,
>
> i'd'like to know if there is a specific pattern for log in order to be
> used with Chainsaw.
>
> My layout is file.log
>
> Thanks for your reply
>
> ---------------------------------------------------------------------
> 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


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