I have project on scala. I use this lib for logging https://github.com/typesafehub/scala-logging
i create logger
import com.typesafe.scalalogging.Logger
val log = Logger(getClass)
and two markers
import org.slf4j.{Marker, MarkerFactory}
private val marker: Marker = MarkerFactory.getMarker("DP")
private val marker2: Marker = MarkerFactory.getMarker("ST")
I use log in my controller
log.debug(marker, "----"
log.debug(marker2, "++++")
This is my logback
<appender name="STDOUTTime" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{30} - %marker - %d{yyyy/MM/dd/HH:mm:ss.SSS/Z} - %message%n%xException{3}</pattern>
</encoder>
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
<Marker>DP</Marker>
<OnMatch>DENY</OnMatch>
<OnMismatch>DENY</OnMismatch>
</turboFilter>
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
<Marker>ST</Marker>
<onMatch>DENY</onMatch>
<onMismatch>DENY</onMismatch>
</turboFilter>
</appender>
<logger name="ds.forwarding" level="DEBUG">
<appender-ref ref="STDOUTTime"/>
</logger>
<root level="ERROR">
</root>
now when i run my controller i have output in console:
[debug] d.f.c.a.s.InputStatisticController - DP - 2017/09/25/11:55:58.603/+0300 - ----
[debug] d.f.c.a.s.InputStatisticController - ST - 2017/09/25/11:55:58.603/+0300 - ++++
Now I have a questions:
- Why marker and marker2 is visible, why DENY does not work?
- How can I exclude two markers?
- How can I exclude only one marker?
Here is a
logback.xml
which denies bothDP
andST
markers.The mistakes about your file:
Your file doesn't start with
<configuration>
and end with</configuration>
Filters are not in the correct namespace. They should be under
<configuration>
(same level with appenders).No need to use
<onMisMatch>
flags in your case. It may cause to mix the things up.Since your logger is named as
ds.forwarding
, in the class you have to be sure that you are calling that logger. In your case, you call the logger withgetClass
method. In mylogback.xml
file, I added theappender
to myroot
logger. Therefore, it is sufficient to call it viaLogger(getClass)
method.Always be careful about levels. I set the level to
DEBUG
.Once you set the configuration properly, simply change the
<onMatch>
property toALLOW
if you want the logger to print it, orDENY
if you don't. Simply setting both toALLOW
will result in printing all the markers, on the other hand, if you set both of them toDENY
, that markers won't be printed.