+slf,act #21671 allow using Markers with LoggingAdapter (#21707)

* +slf,act #21671 allow using Markers with LoggingAdapter

* +slf,act #21671 allow using Markers with LoggingAdapter

* improve compatibility

* add docs

* address review comments

* actually print the marker
This commit is contained in:
Konrad Malawski 2016-10-27 15:07:59 +02:00 committed by GitHub
parent 650abe19d6
commit 3951cf4e68
13 changed files with 1420 additions and 80 deletions

View file

@ -446,7 +446,7 @@ get it you will use the factory receiving an Actor as logSource:
val log: DiagnosticLoggingAdapter = Logging(this);
Once you have the logger, you just need to add the custom values before you log something.
This way, the values will be put in the SLF4J MDC right before appending the log and removed after.
This way, the values will dologbe put in the SLF4J MDC right before appending the log and removed after.
.. note::
@ -473,3 +473,24 @@ Now, the values will be available in the MDC, so you can use them in the layout
</encoder>
</appender>
Using Markers
-------------
Some logging libraries allow, in addition to MDC data, attaching so called "markers" to log statements.
These are used to filter out rare and special events, for example you might want to mark logs that detect
some malicious activity and mark them with a ``SECURITY`` tag, and in your appender configuration make these
trigger emails and other notifications immediately.
Markers are available through the LoggingAdapters, when obtained via ``Logging.withMarker``.
The first argument passed into all log calls then should be a ``akka.event.LogMarker``.
The slf4j bridge provided by akka in ``akka-slf4j`` will automatically pick up this marker value and make it available to SLF4J.
For example you could use it like this::
<pattern>%date{ISO8601} [%marker][%level] [%msg]%n</pattern>
A more advanced (including most Akka added information) example pattern would be::
<pattern>%date{ISO8601} level=[%level] marker=[%marker] logger=[%logger] akkaSource=[%X{akkaSource}] sourceActorSystem=[%X{sourceActorSystem}] sourceThread=[%X{sourceThread}] mdc=[ticket-#%X{ticketNumber}: %X{ticketDesc}] - msg=[%msg]%n----%n</pattern>