
Ceki, just tried my custom MarkerConverter but I got an error: ERROR in ch.qos.logback.core.pattern.parser.Compiler@26312 - [bundlemarker] is not a valid conversion word --------- from my config file: ... <conversionRule conversionWord="bundlemarker" converterClass="org.ekkehard.logback.util.BundleMarkerConverter"/> ... <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%d{HH:mm:ss.SSS} %-5level [%logger{40}] %bundlemarker %msg%n</Pattern> </layout> </appender> ----- perhaps the problem is that my BundleMarkerConverter class was not found - all runs under OSGI what do you think - should I add the import to logback core or logback classic ? or could something else be wrong because the error notes that the conversion word wasn't valid and not that class BundleMarkerConverter wasn't found thanks ekke ekkehard schrieb:
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 _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user