[logback-user] Log by transaction, rather than logger/class

Jeff Jensen jjensen at apache.org
Mon Nov 3 17:49:50 CET 2014


Start of ideas for you:
1. The getLogger(name) method is overloaded, and one of them has a param of
a String, so you can name it anything you want, e.g. the transaction name.
Difference is, obtain the logger at the start of the execution instead of
at the class' instantiation (e.g. as an instance variable), and definitely
not as a static logger.  This has "logger name" as the transaction name.

2. Use MDC [0], [1] and add the transaction name as an MDC variable at the
transaction start.  This has "transaction name" as one of the data items in
every log message.  For example, all my web apps have an MDC for user name,
so all user-related logging has the user name in it, enabling seeing single
user's path through the system when troubleshooting.


Perhaps this is enough of an idea to get you going in a useful direction?


[0] http://logback.qos.ch/manual/mdc.html
[1] http://www.slf4j.org/api/org/slf4j/MDC.html


On Mon, Nov 3, 2014 at 10:07 AM, Donald McLean <dmclean62 at gmail.com> wrote:

> I am working on a multi-threaded web app and I use Logback for debugging
> purposes during development.
>
> Most of what happens in my app is event driven, and there is a clear start
> and end point of the processing of each event. All of the processing that
> takes place on a given thread between the start and end point are all part
> of the same event/transaction.
>
> So what I would find helpful is if there was a way to configure Logback so
> that logging was different inside a transaction (even if it just turned on
> all logging) and that the rules were based on the transaction name rather
> than on the debugger.
>
> Would something like this be reasonably possible?
>
> Just curious,
>
> Donald
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20141103/8e537574/attachment.html>


More information about the Logback-user mailing list