scm-spain / karyon2-accesslog

0 stars 1 forks source link

Logging using Mapped Diagnostic Context #20

Open padilo opened 8 years ago

padilo commented 8 years ago

Maybe a good idea to move to use MDC which basically consists on having a Map of key value with context variables that can be used to log, and can be formatted using the logger configuration.

The basic implementation of MDC that comes with logback, log4j and maybe in other slf4j implementations is using ThreadLocal variables which is not a good idea if using karyon, as many threads may be involved in the resolution of a request, but there are manners to solved this using onScheduler event that rxJava provides and propagate the context map on each thread, take a look at this

I don't know if this works with rxnetty too, as I read somewhere it uses a different event loop, but at least it could be quite interesting to try to check if this is possible, because using MDC we will have context information on every log the application sends.

Of course using this implementation is not free in terms of efficiency but it will add more information to the each log trace and will be very helpful to diagnose problems in applications.