Hi Remko,

How can we add values to thread context maps with commons API ?

Thanks!
Regards.

On Sat, May 9, 2015 at 11:48 AM, Remko Popma <[email protected]> wrote:

> I added the above mention to the migration guide.
> Also added a link to custom log levels to the manual introduction page.
>
> On Sat, May 9, 2015 at 4:40 AM, Gary Gregory <[email protected]>
> wrote:
>
>>
>> On Fri, May 8, 2015 at 12:39 AM, Remko Popma <[email protected]>
>> wrote:
>>
>>> Ok that's a good idea. The current migration guide does not mention that
>>> log4j-1.x MDC and NDC (
>>> https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/MDC.html)
>>> have been replaced by log4j2's ThreadContext.
>>>
>>
>> Remko: Are you planning on updating the docs?
>>
>> Gary
>>
>>>
>>>
>>> Sent from my iPhone
>>>
>>> On 2015/05/08, at 14:43, Chathura Priyankara <[email protected]>
>>> wrote:
>>>
>>> Hi Remko,
>>>
>>> Thank you very much for the explanation.
>>> That was exactly what I needed.
>>> I think it is better if those information can be included the log4j2
>>> documentation in the migrating from log4j 1.2 section because most of the
>>> applications are still using log4j 1.2.x and need to convert to log4j2.
>>> No need to add long descriptions but just adding feature mappings
>>> between log4j 1.2 and log4j2 is enough I think.
>>>
>>> Regards,
>>> Chathura.
>>>
>>> On Fri, May 8, 2015 at 10:55 AM, Remko Popma <[email protected]>
>>> wrote:
>>>
>>>> Thanks for the additional detail.
>>>> With log4j-1.x, a custom appender may have been the best solution, but
>>>> it sounds like log4j2's built-in features provide all you need.
>>>>
>>>> If your application calls
>>>> ThreadContext.put("serviceId", getServiceId());
>>>> ThreadContext.put("serviceName", getServiceName());
>>>> // etc
>>>>
>>>> ...then if you configure this pattern in the ConsoleAppender layout:
>>>> <PatternLayout pattern="%d %p %m %X{serviceId} %X{serviceName}" />
>>>>
>>>> ...you will see the values that your application put in
>>>> the ThreadContext map appear in the logs.
>>>>
>>>> This does not require a custom appender or custom log events.
>>>>
>>>> Sent from my iPhone
>>>>
>>>> On 2015/05/08, at 14:00, Chathura Priyankara <[email protected]>
>>>> wrote:
>>>>
>>>> Hi All,
>>>>
>>>> Thank you for the replies.
>>>> Currently I'm migrating a large application from log4j 1.2.17 to log4j
>>>> 2.2.
>>>> That application has custom console appender which takes logging event
>>>> and create custom logging events with some additional application specific
>>>> data such as service id, service name etc.
>>>> Then it uses custom pattern layout to log those information.
>>>> Now I want to migrate this scenario to log4j2.
>>>>
>>>> Can you please provide a brief guidance on this ?
>>>>
>>>> Thanks!
>>>> Chathura.
>>>>
>>>> On Fri, May 8, 2015 at 4:00 AM, Remko Popma <[email protected]>
>>>> wrote:
>>>>
>>>>> You may not need to write a custom appender. Have you looked at the
>>>>> ThreadContext map? Your application threads can put key-value pairs in 
>>>>> that
>>>>> map, and following that, all log events generated by that thread will 
>>>>> carry
>>>>> those key-value pairs. You can output the values with the %X pattern in
>>>>> your pattern layout.
>>>>>
>>>>> Remko
>>>>>
>>>>> Sent from my iPhone
>>>>>
>>>>> On 2015/05/07, at 22:14, Chathura Priyankara <[email protected]>
>>>>> wrote:
>>>>>
>>>>> Hi Beharooz,
>>>>>
>>>>> I want to log some application specific data such as domain, userid
>>>>> etc using custom console appender.
>>>>> Is this possible ?
>>>>>
>>>>> Thanks!
>>>>>
>>>>> On Thu, May 7, 2015 at 5:20 PM, Behrooz Nobakht <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> What is the customization that you wanna apply?
>>>>>>
>>>>>> Cheers,
>>>>>> Behrooz
>>>>>>
>>>>>>
>>>>>> On Thu, May 7, 2015 at 1:26 PM, Chathura Priyankara <
>>>>>> [email protected]> wrote:
>>>>>>
>>>>>>> Hi devs,
>>>>>>>
>>>>>>> I want to create a custom console appender for log4j2 but I cannot
>>>>>>> find any resource or sample about this. The only resource [1] is not 
>>>>>>> enough
>>>>>>> for this.
>>>>>>>
>>>>>>> [1]
>>>>>>> https://logging.apache.org/log4j/2.x/manual/extending.html#Appenders
>>>>>>>
>>>>>>> Can anyone provide me a sample for this ? (both configuration and
>>>>>>> custom appender)
>>>>>>>
>>>>>>> Any help is appreciated.
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>> --
>>>>>>> Chathura Priyankara,
>>>>>>> Faculty of Information Technology,
>>>>>>> University of Moratuwa.
>>>>>>> Blog  : www.codeoncloud.blogspot.com
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> -- Behrooz Nobakht
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Chathura Priyankara,
>>>>> Faculty of Information Technology,
>>>>> University of Moratuwa.
>>>>> Blog  : www.codeoncloud.blogspot.com
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Chathura Priyankara,
>>>> Faculty of Information Technology,
>>>> University of Moratuwa.
>>>> Blog  : www.codeoncloud.blogspot.com
>>>>
>>>>
>>>
>>>
>>> --
>>> Chathura Priyankara,
>>> Faculty of Information Technology,
>>> University of Moratuwa.
>>> Blog  : www.codeoncloud.blogspot.com
>>>
>>>
>>
>>
>> --
>> E-Mail: [email protected] | [email protected]
>> Java Persistence with Hibernate, Second Edition
>> <http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>


-- 
Chathura Priyankara,
Faculty of Information Technology,
University of Moratuwa.
Blog  : www.codeoncloud.blogspot.com

Reply via email to