How does conversion discovery work in canonical logback?

35 Views Asked by At

I'm looking at https://logback.qos.ch/manual/layouts.html#customConversionSpecifier.

In step 2 it says

we must let logback know about the new Converter. For this purpose, we need to declare the new conversion word in the configuration file, as shown below

The Legacy example config is as follows:

<configuration>

  <conversionRule conversionWord="nanos"
                  converterClass="chapters.;layouts.MySampleConverter" />

  <appender name="STDOUT" class="ch.qos.logback.;core.ConsoleAppender">
    <encoder>
      <pattern>%-6nanos [%thread] -%kvp -%msg%n</pattern>
    </encoder>
  </appender>

  <root level="DEBUG">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

In that configuration, it's very easy to see how the "new conversion word" is declared: with the conversionRule element. In the Canonical (1.3) example, however, no such element exists:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>

<configuration>
  <import class="ch.qos.logback.;core.ConsoleAppender"/>
  <import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>

  <appender name="STDOUT" class="ConsoleAppender">
    <encoder class="PatternLayoutEncoder">
      <pattern>%-6nanos [%thread] -%kvp -%msg%n</pattern>
    </encoder>
  </appender>

  <root level="DEBUG">
    <appender-ref ref="STDOUT"/>
  </root>
</configuration>

There's no declaration of any nanos conversion word, and no reference to the custom converter at all. I've also noticed that for any config including conversionRule, if I put it through the canonicalizer (which transforms logback.xml files into canonical form) any reference to conversionRule and the conversionWord and converterClass is dropped entirely.

I can't find anything that explains how to specify or provide conversion rules in the canonical format. Is this a problem with the documentation/canonicalizer, or is there some behind-the-scenes magic that goes on that allows these to be equivalent despite the lack of any reference to MySampleConverter in the canonical configuration?

0

There are 0 best solutions below