[logback-user] Custom Logger for logging custom object?

ceki ceki at qos.ch
Mon Jul 9 15:17:03 CEST 2012


Hi Adam,

You can perform the toString() conversion with the help of a customer 
converter [1]. More specifically, you would create a converter replacing 
%msg / %message.

HTH,

[1] http://logback.qos.ch/manual/layouts.html#customConversionSpecifier

-- 
Ceki
http://twitter.com/#!/ceki


On 09.07.2012 14:43, Adam Brightwell wrote:
> Hey Andrzej,
>
> Thanks for the suggestion.  I agree that this would be a straight
> forward solution.  Unfortunately, overriding the toString() method will
> not work as the format of the log message must be configurable.  Much in
> the same way that you can configure the format of a log message using
> the PatternLayout.  For obvious reasons, I believe the format and the
> message data should be independent of each other.  Thanks again, I
> appreciate the quick response.
>
> Thanks,
> Adam
>
> From: Andrzej Zadorozny <andrzej.zadorozny at gmail.com
> <mailto:andrzej.zadorozny at gmail.com>>
> Date: Friday, July 6, 2012 10:20 PM
> To: Adam Brightwell <abrightwell at lce.com <mailto:abrightwell at lce.com>>
> Subject: Re: [logback-user] Custom Logger for logging custom object?
>
> Hi Adam,
>
> If you could have the POJOs implement their own toString() method (if
> it's possible in your situation), I think that would be a straight
> forward solution.
>
> CheerZ! :)
>
>
> On Fri, Jul 6, 2012 at 7:15 PM, Adam Brightwell <abrightwell at lce.com
> <mailto:abrightwell at lce.com>> wrote:
>
>     Hey All,
>
>     I have an interesting logging requirement in front of me.  I am
>     required to log application specific information that is contained
>     within a custom POJO.  The developers will create and fill these
>     POJO's with the appropriate information when a logging "event" takes
>     place.  The hope was that it could then be passed off to our logging
>     system and it would know what to do with it.  However, the obvious
>     problem is that Logger can't be overridden to allow the overloading
>     of the info, warn, error, etc. methods to receive the custom POJO.
>       I have considered simply implementing the "Delegation Pattern"
>     implementing the slf4j Logger interface and wrapping the logback
>     Logger which would allow me to simply overload the necessary
>     methods.  I was curious what the communities thoughts might be on
>     this potential solution.  Are there other recommendations that might
>     work better for my purposes?  Any help, recommendations or guidance
>     would be greatly appreciated.
>
>     Thanks,
>     Adam
>
>
> --
> Andrzej Zadorozny
>
>
>



More information about the Logback-user mailing list