<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">SWEET!</div><div class=""><br class=""></div><div class="">thanks Ceki. My guess is other people will want to do the same thing. bellow is my working code. </div><div class=""><br class=""></div><div class="">background. I have a CLI java application. I want to generate all output using logger instead of System.out or System.error. I want logger.info() to be un decorated. All other levels of logging should level, class and line #</div><div class=""><br class=""></div><div class="">Thanks</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Andy</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""><span style="color: rgb(147, 26, 104);" class="">public</span> <span style="color: rgb(147, 26, 104);" class="">class</span> DebugConverter <span style="color: rgb(147, 26, 104);" class="">extends</span> CompositeConverter<ILoggingEvent> {</span></div><div style="margin: 0px; font-family: Monaco; min-height: 25px;" class=""><span style="font-size: 12px;" class=""><br class=""></span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> <span style="color: #931a68" class="">public</span> DebugConverter() {</span></div><div style="margin: 0px; font-family: Monaco; color: rgb(78, 144, 114);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span>// <span style="color: #91afcb" class="">TODO</span> Auto-generated constructor stub</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> }</span></div><div style="margin: 0px; font-family: Monaco; min-height: 25px;" class=""><span style="font-size: 12px;" class=""><br class=""></span></div><div style="margin: 0px; font-family: Monaco; color: rgb(119, 119, 119);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span>@Override</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> <span style="color: #931a68" class="">protected</span> String transform(ILoggingEvent <span style="color: #7e504f" class="">event</span>, String <span style="color: #7e504f" class="">in</span>) {</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> <span style="color: #931a68" class="">if</span> (Level.<span style="color: #0326cc" class="">INFO</span> == <span style="color: #7e504f" class="">event</span>.getLevel()) {</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> <span style="color: #931a68" class="">return</span> <span style="color: #3933ff" class="">""</span>;</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> }</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> StringBuilder <span style="color: #7e504f" class="">sb</span> = <span style="color: #931a68" class="">new</span> StringBuilder();</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> <span style="color: #7e504f" class="">sb</span>.append(<span style="color: #7e504f" class="">in</span>);</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> String <span style="color: #7e504f" class="">ret</span> = <span style="color: #7e504f" class="">sb</span>.toString();</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> <span style="color: #931a68" class="">return</span> <span style="color: #7e504f" class="">ret</span>;</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> }</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class="">}</span></div></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""><br class=""></span></div><div style="margin: 0px; font-family: Monaco;" class=""><div style="margin: 0px; color: rgb(78, 145, 146);" class=""><span style="font-size: 12px;" class=""><span style="color: #009193" class=""><</span>configuration<span style="color: #009193" class="">></span></span></div><div style="margin: 0px; color: rgb(78, 145, 146);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre"> </span></span><span style="color: #009193" class=""><</span>conversionRule<span style="color: #000000" class=""> </span><span style="color: #932192" class="">conversionWord</span><span style="color: #000000" class="">=</span><span style="color: #3933ff" class="">"AST_DEBUG"</span><span style="color: #000000" class=""> </span></span></div><div style="margin: 0px; color: rgb(57, 51, 255);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span><span style="color: #932192" class="">converterClass</span><span style="color: #000000" class="">=</span>"com.apple.ast.logging.converter.DebugConverter"<span style="color: #000000" class=""> </span><span style="color: #009193" class="">/></span></span></div><p style="margin: 0px; min-height: 25px;" class=""><span style="font-size: 12px;" class=""> <br class="webkit-block-placeholder"></span></p><div style="margin: 0px; color: rgb(57, 51, 255);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span><span style="color: #009193" class=""><</span><span style="color: #4e9192" class="">appender</span><span style="color: #000000" class=""> </span><span style="color: #932192" class="">name</span><span style="color: #000000" class="">=</span>"STDOUT"<span style="color: #000000" class=""> </span><span style="color: #932192" class="">class</span><span style="color: #000000" class="">=</span>"ch.qos.logback.core.ConsoleAppender"<span style="color: #009193" class="">></span></span></div><div style="margin: 0px;" class=""><span style="font-size: 12px;" class=""> <span style="color: #009193" class=""><</span><span style="color: #4e9192" class="">encoder</span><span style="color: #009193" class="">></span></span></div><div style="margin: 0px;" class=""><span style="font-size: 12px;" class=""> <span style="color: #009193" class=""><</span><span style="color: #4e9192" class="">pattern</span><span style="color: #009193" class="">></span>%AST_DEBUG(%-5level [%class{16}] [line:%L]) %m%n<span style="color: #009193" class=""></</span><span style="color: #4e9192" class="">pattern</span><span style="color: #009193" class="">></span></span></div><div style="margin: 0px;" class=""><span style="font-size: 12px;" class=""> <span style="color: #009193" class=""></</span><span style="color: #4e9192" class="">encoder</span><span style="color: #009193" class="">></span></span></div><div style="margin: 0px; color: rgb(78, 145, 146);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span><span style="color: #009193" class=""></</span>appender<span style="color: #009193" class="">></span></span></div><div style="margin: 0px; min-height: 25px;" class=""><span style="font-size: 12px;" class=""><br class=""></span></div><div style="margin: 0px; color: rgb(57, 51, 255);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span><span style="color: #009193" class=""><</span><span style="color: #4e9192" class="">root</span><span style="color: #000000" class=""> </span><span style="color: #932192" class="">level</span><span style="color: #000000" class="">=</span>"DEBUG"<span style="color: #009193" class="">></span></span></div><div style="margin: 0px; color: rgb(78, 145, 146);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span><span style="color: #009193" class=""><</span>appender-ref<span style="color: #000000" class=""> </span><span style="color: #932192" class="">ref</span><span style="color: #000000" class="">=</span><span style="color: #3933ff" class="">"STDOUT"</span><span style="color: #000000" class=""> </span><span style="color: #009193" class="">/></span></span></div><div style="margin: 0px;" class=""><span style="font-size: 12px;" class=""> <span style="color: #009193" class=""></</span><span style="color: #4e9192" class="">root</span><span style="color: #009193" class="">></span></span></div><div style="margin: 0px; color: rgb(78, 145, 146);" class=""><span style="font-size: 12px;" class=""><span style="color: #009193" class=""></</span>configuration<span style="color: #009193" class="">></span></span></div><div class=""><span style="color: rgb(0, 145, 147); font-size: 12px;" class=""><br class=""></span></div><div class=""><div style="margin: 0px; color: rgb(119, 119, 119);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span>@Test</span></div><div style="margin: 0px;" class=""><span style="font-size: 12px;" class=""> <span style="color: #931a68" class="">public</span> <span style="color: #931a68" class="">void</span> testLogger() {</span></div><div style="margin: 0px; color: rgb(57, 51, 255);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span><span style="color: #0326cc" class="">logger</span><span style="color: #000000" class="">.debug(</span>"debug {}"<span style="color: #000000" class="">, </span>"testLogger"<span style="color: #000000" class="">);</span></span></div><div style="margin: 0px; color: rgb(57, 51, 255);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span><span style="color: #0326cc" class="">logger</span><span style="color: #000000" class="">.info(</span>"info {}"<span style="color: #000000" class="">, </span>"testLogger"<span style="color: #000000" class="">);</span></span></div><div style="margin: 0px; color: rgb(57, 51, 255);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span><span style="color: #0326cc" class="">logger</span><span style="color: #000000" class="">.warn(</span>"warn {}"<span style="color: #000000" class="">, </span>"testLogger"<span style="color: #000000" class="">);</span></span></div><div style="margin: 0px; color: rgb(57, 51, 255);" class=""><span style="font-size: 12px;" class=""><span style="color: #000000" class=""> </span><span style="color: #0326cc" class="">logger</span><span style="color: #000000" class="">.error(</span>"error {}"<span style="color: #000000" class="">, </span>"testLogger"<span style="color: #000000" class="">);</span></span></div><div style="margin: 0px;" class=""><span style="font-size: 12px;" class=""> }</span></div></div></div><div class=""><span style="font-size: 12px;" class=""><br class=""></span></div><div class=""><span style="font-size: 12px;" class=""><br class=""></span></div><div class=""><span style="font-size: 12px;" class="">generates following output</span></div><div class=""><span style="font-size: 12px;" class=""><br class=""></span></div><div class=""><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class="">DEBUG [c.a.a.CustomDelimitedFileSourceTest] [line:120] debug testLogger</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class=""> info testLogger</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class="">WARN [c.a.a.CustomDelimitedFileSourceTest] [line:122] warn testLogger</span></div><div style="margin: 0px; font-family: Monaco;" class=""><span style="font-size: 12px;" class="">ERROR [c.a.a.CustomDelimitedFileSourceTest] [line:123] error testLogger</span></div></div><div class=""><span style="font-size: 12px;" class=""><br class=""></span></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 15, 2015, at 3:23 AM, Ceki Gülcü <<a href="mailto:ceki@qos.ch" class="">ceki@qos.ch</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">Hi Andy,<br class=""><br class="">When you write "%a(%x %y)" then %x and %y are child converters for %a. So, in the case of "%debug(%level %d %t)", the converters %level,%d and %t are children of %debug. %debug is said to be a composite converter and the parenthesis () is sort of a composition operator.<br class=""><br class="">For your particular case, you need to sub-class CompositeConverter. See the implementation for HighlightingCompositeConverter (and ForegroundCompositeConverterBase). Look at the code for CompositeConverter ND notice how the convert() method of CompositeConverter delegates to child converters and only at the end transforms the results.<br class=""><br class="">I hope this helps,<br class=""><br class="">--<br class="">Ceki<br class=""><br class="">On 4/15/2015 3:12, Andrew E. Davidson wrote:<br class=""><blockquote type="cite" class="">Hi Ceki<br class=""><br class=""><br class=""><blockquote type="cite" class=""><br class="">Alternatively, you could write a custom conversion specifier. If you<br class="">had a specifier called %debug which output contents only for level<br class="">DEBUG, and a %warn specifier which output contents only for level WARN<br class="">and another specifier %ERROR which output contents for ERROR, your<br class="">pattern could be written as<br class=""><br class="">%debug(%level %d %t) %error(%level) %info(%level) %m%n<br class=""><br class="">See <a href="http://logback.qos.ch/manual/layouts.html#customConversionSpecifier" class="">http://logback.qos.ch/manual/layouts.html#customConversionSpecifier</a><br class="">for documentation on this topic.<br class=""><br class=""></blockquote><br class="">I tried your custom conversion specifier approach. I think I am<br class="">missing something. In your logback.xml it looks like you are able to<br class="">pass arguments. I used a debugger how ever it did not appear like the<br class="">the ILoggingEvent had anything particularly useful other then the level<br class="">and thread Name values. List<String> optionList= getOptionList(); gives<br class="">me [%level %d %t] how ever the values have not been expanded<br class=""><br class="">Your solution is very close to what I want to do.<br class=""><br class="">Thanks in advance<br class=""><br class="">Andy<br class=""><br class="">public class DebugConverter extends ClassicConverter {<br class="">public DebugConverter() {<br class="">// TODO Auto-generated constructor stub<br class=""> }<br class=""><br class="">@Override<br class="">public String convert(ILoggingEvent event) {<br class="">List<String> optionList = getOptionList();<br class="">Levellevel=event.getLevel();<br class=""> System.err.println("convert() level:" + level);<br class="">return"DebugConverter.convert()";<br class=""> }<br class="">}<br class=""><br class=""><configuration><br class=""><conversionRuleconversionWord="AST_DEBUG"<br class="">converterClass="com.apple.ast.logging.converter.DebugConverter"/><br class=""><br class=""><br class=""><appendername="STDOUT"class="ch.qos.logback.core.ConsoleAppender"><br class=""><encoder><br class=""><!--<br class=""> <pattern>%-5level %date{HH:mm:ss,SSS} [%thread]<br class="">[%class{16}] [line:%L] %msg%n</pattern><br class=""> --><br class=""><pattern>%AST_DEBUG{%level %d %t} %m%n</pattern><br class=""></encoder><br class=""></appender><br class=""><br class=""><rootlevel="DEBUG"><br class=""><appender-refref="STDOUT"/><br class=""></root><br class=""></configuration><br class=""></blockquote>_______________________________________________<br class="">Logback-user mailing list<br class=""><a href="mailto:Logback-user@qos.ch" class="">Logback-user@qos.ch</a><br class="">http://mailman.qos.ch/mailman/listinfo/logback-user<br class=""></div></blockquote></div><br class=""></body></html>