
Ceki Gulcu schrieb:
Hi Ekke,
Here is the code for MarkerConverter:
======= Start MarkerConverter.hava ======== package ch.qos.logback.classic.pattern;
import org.slf4j.Marker;
import ch.qos.logback.classic.spi.LoggingEvent;
/** * Return the event's marker value(s). * * @author Sébastien Pennec */ public class MarkerConverter extends ClassicConverter {
private static String EMPTY = "";
public String convert(LoggingEvent le) { Marker marker = le.getMarker(); if (marker == null) { return EMPTY; } else { return marker.toString(); } } } ======= End MarkerConverter.hava ========
Studying the code above, I would say that you have two options. First, just remove the [] from the conversion pattern. So instead of writing
"%d %level [%marker] - %msg%n"
as you conversion pattern, just write
"%d %level %marker - %msg%n"
You second option is to write your own converter for handling markers. You could modify it to return an empty string if there is no marker, and to return "["+marker.toString()+"]" if there is a marker in the event. Here is sample code:
package de.gentz-software.logback;
import org.slf4j.Marker; import ch.qos.logback.classic.spi.LoggingEvent;
public class MyMarkerConverter extends ClassicConverter {
private static String EMPTY = "";
public String convert(LoggingEvent le) { Marker marker = le.getMarker(); if (marker == null) { return EMPTY; } else { return "["+marker.toString()+"]"; } } }
You also need to let logback know about your conversion word. Here is how:
<conversionRule conversionWord="myMarker" converterClass="de.gentz-software.logback.MyMarkerConverter"/>
Here is a sample config file:
<configuration> <conversionRule conversionWord="myMarker" converterClass="de.gentz-software.logback.MyMarkerConverter" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%-4relative [%thread] %myMarker - %msg%n</Pattern> </layout> </appender>
<root> <level value="debug" /> <appender-ref ref="STDOUT" /> </root> </configuration>
I hope this helps,
of course - thanks :-) ...gives me some more ideas how to solve it best to print OSGI bundle-name and service-name I put into the Marker-tree ekke