[logback-user] how to override the LogbackMDCAdapter

Matt Young solid at youngdev.net
Fri Oct 11 05:01:22 CEST 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I am having trouble overriding the LogbackMDCAdapter.  No matter what
happens, MDC.getAdapter().getClass() returns
ch.qos.logback.classic.util.LogbackMDCAdapter
It is important to mention that I am using slf4j with logback.  Here is
my config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %C:%L
%msg%n</pattern>
    </encoder>
  </appender>
  <appender name="jobLoggerAppender"
class="ch.qos.logback.classic.sift.SiftingAppender">
 
 
    <discriminator
class="ch.qos.logback.classic.sift.MDCBasedDiscriminator">
        <key>jobGroup</key>
        <key>jobName</key>
        <key>jobId</key>
        <defaultValue>unknown</defaultValue>
       
    </discriminator>
       
        <sift>
            <appender  name="${jobGroup}-${jobName}-${jobId}"
class="ch.qos.logback.core.FileAppender">
                <file>${jobGroup}/${jobName}/${jobId}.log</file>
                <layout class="ch.qos.logback.classic.PatternLayout">
                    <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level
[%thread] %C:%L %msg%n</pattern>
                </layout>
            </appender>
        </sift>
    </appender>


  <!-- Strictly speaking, the level attribute is not necessary since -->
  <!-- the level of the root level is set to DEBUG by default.       -->
  <root level="DEBUG">         
    <appender-ref ref="STDOUT" />
    <appender-ref ref="FILE" />
  </root>
  <logger name="jobLogger" level="debug" >
      <appender-ref ref="jobLoggerAppender"/>
  </logger>
 
</configuration>

As you can see, I do have the class attribute set on the decriminator. 
And I use the slf4j MDC class to put() the 3 values jobGroup, jobName
and jobId in the MDC.  Any ideas?

- -- 
Cheers,
Matt Young
solid at youngdev.net
http://youngdev.net

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJSV2oCAAoJEO5jycTTPEzc9WsP/3LhDRkAcSrmj3ErxfhqfY1b
s4+irKclxjHzfYItoxDKc0LhPPfm4QM0aU17gwbR4a6hjBK5coMEWYRRZsB94OuO
g3XsnWjvELbuaexXqpAm0Gep7iqBUm57/gi96Jb0SJZSCoInn1b0oMBzydKWSgJe
lU9YLgoI+m4Mk6o+qPdrMtZvErNeLuleMru45g5bAl/KvDpCnYP5t3ErKqOukkUz
1rJsE6mx8e8g/VVtQXFk77gmSkuoVXynOuBI5c6NvQEbtoBawqVckvI9HcYHqIE6
7w+PXmIn4r6l9vs9KYz4kNQ2wBL007vGTDfyx2ZC/AhoqgFXNX/PDGC8rIWhMnG8
BCGqs+4EjKhazzpT9XSv7fU99SQ0e0qPhGfa7g/MDfPMsZWjKChoiRMnHEKD4YHr
xJQm6YxnlBpyxg8+LNKLfwdBNNiHNa47uw+BaFQNslAG0FC+/qM+7M8kxa8KjkAW
zU/Hsi+ZCpECaMZ5w2v2Hn+4ZIoKPG+wUrEYH600TM9isanLeNfDXlVPTfvozSMu
VEm5y/wmPoZiAZfP0Dkmkx6sMHR48ccYdV+o0q7R8N4NwnETiTbITS/xE/nkSNwh
YgDdG8wvv/yJaByNGBRAXD7NCT8wCwCTzZpglfTZjA8NdXebsctMgGCrINnRuYLl
5BtLgxc5DzBVaYdB+jZ5
=A65C
-----END PGP SIGNATURE-----



More information about the Logback-user mailing list