With RollingFileAppender , I am not getting any log - MDC keys. ( I
have given the pattern %X{Key}...
Any idea ?
-----Original Message-----
From: Paul Smith [mailto:[EMAIL PROTECTED]
Sent: Monday, December 12, 2005 2:44 AM
To: Log4J Users List
Subject: Re: How to carry fwd log messages from multiple Loggers to a
single logger
The usual way I would do this is use MDC. What you require is to be
able to correlate separate logging events together (at least be able
to find them easily).
IN this case I'm guessing you have a unique Order identified (say,
OrderID). In the bit of code where you first know the OrderID, do this:
Integer orderID = ........;
MDC.put("OrderID", orderID);
At each layer,just log whatever you want to log, knowing that the MDC
values are assigned to each loggingevent on the same thread.
Then, to be able to correlate the information in your log files, you
need to output the MDC value. Using PatternLayout, the %X value
gives you access to MDC values, so adding %X{OrderID} would display
on each line the value of the OrderID value you assigned. You won't
get all of the events on the same line of logs, but this is much much
easier. This is the way I log all events in a webapplication frame
work, logging the userID via mDC to be able to correlate what
happened for a given request.
The last step is to find a logical place in your thread's code to
clear the MDC value, so that if the same thread is used again, it's
value is not polluted:
MDC.remove("OrderID");
cheers,
Paul Smith
On 10/12/2005, at 5:44 PM, Sriram Venkatasubramanian wrote:
> Hi ,
>
> I have a distinct logger at three layer ( DAO, Service, Controller)
> which all writing to one file as
>
>
>
> DEBUG 2005-12-09 19:29:37,422 Create Order: DAO :1301
>
> DEBUG 2005-12-09 19:29:37,429 Create Order: Service :35
>
> DEBUG 2005-12-09 19:29:37,432 Create Order: Controller :51
>
>
>
> I would like to get the log as a single line as
>
>
>
> [03/Oct/2003:09:11:29 -0700] Create Order : Controller[5ms] ,
> [03/Oct/2003:09:11:29 -0700] Create Order : Service[25 MS]
> [03/Oct/2003:09:11:29 -0700] Create Order : DAO[25 MS]
>
>
>
> I think I have to carry fwd each log messages from each logger and
> finally write in one place. Is it psble ? Any idea how ?
>
>
>
> I am using RollingFileAppender as
>
>
>
> <appender name="ACPTORDER_CONTROLLER"
> class="org.apache.log4j.RollingFileAppender">
>
> <param name="File"
> value="${oracle.j2ee.home}/log/portal/monitoring/AppMonitoring.log"/>
>
> <param name="Append" value="false"/>
>
> <param name="DatePattern" value="'.'yyyy-MM-dd"/>
>
> <param name="MaxFileSize" value="2MB"/>
>
> <param name="MaxBackupIndex" value="10"/>
>
> <layout class="org.apache.log4j.PatternLayout">
>
> <param name="ConversionPattern" value="%-5p %d %m%
> n"/>
>
>
> </layout>
>
> </appender>
>
>
>
>
>
> Regards,
>
> Sriram V
>
>
>
>
>
>
>
>
>
>
>
>
>
> Sriram V
>
> [EMAIL PROTECTED]
>
> Adea International Pvt Ltd,
> CMMi Level 5 Company
>
> No.319/1, Bommanahalli
> Hosur Main Road
> Begur Hobli
> Bangalore - 560 095
>
> Tel : +91 80 5199 2332
> +91 80 5199 2258 (Direct line)
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]