[logback-user] custom fields
Mel T
machintruc at gmail.com
Tue Aug 11 21:25:42 CEST 2009
Ceki Gulcu wrote:
>
> You can pass data to your custom appender via two SLF4J primitives.
>
> 1) via MDC
>
> [...]
>
> 2) via Parameters to the printing methods of a logger
>
> [...]
>
I was going to pick option 2, but just realized that there is no API in
slf4j Logger to have both the parameters for formatted message AND a
Throwable.
I can also see that this has been an ongoing debate, therefore I believe
that my use case would provide an argument for those pushing to get that
API.
Mel T. wrote:
>
>> Hi,
>>
>> We have an in-house logger that we want to get rid of. This logger has
>> application specific functionality.
>>
>> - We store logs in a database table
>>
>> - We have specific columns that put some very-frequently used context
>> information
>>
>> - For that purpose, our logger has methods like this:
>> log(String message, String someContextID1, String someContextID2,
>> ...);
>>
>> - This is added to the DB with specific columns for someContextID1,
>> someContextID2, etc...
>>
>> - We have a log viewer that allows to select logs based on that
>> context information.
>>
>> So we need an appender that will continue to fill up that same table.
>>
>> If we move to a logger like logback, I am unsure how to best handle
>> our application need.
>>
>> This first comes to mind:
>>
>> - Create our own facade that adds the specific log methods (like above)
>> - This facade assembles these arguments into a parsable message given
>> to sfl4j/logback
>> - An in-house DBAppender can parse the message to extract the
>> arguments and store them in the right column.
>>
>> Or is there a more natural way to do that?
>>
>> I looked at markers, MDC, but is is not clear to me if any of them
>> would be good for that. Maybe MDC could be used that way:
>>
>> - Create our own facade that adds the specific log methods (like above)
>> - This facade assembles these arguments and places them in MDC
>> - An in-house DBAppender can read the MDC and store values in the right
>> column.
>>
>> Also, is'nt adding another facade on top of SLF4J/logback a little too
>> much? Since we may add out own facade, should'nt we directly use
>> logback?
>>
>
--
View this message in context: http://www.nabble.com/custom-fields-tp24598967p24924171.html
Sent from the Logback User mailing list archive at Nabble.com.
More information about the Logback-user
mailing list