私が質問を投稿した後、Tony はここで優れた回答を提供してくれました。
http://old.nabble.com/Enable-Debugging-Mode-Programmatically--td32961424.html
これは、特定のケースで LogBack が機能しない理由を理解しようとするときに非常に役立ちます。初期化コードには最初の方法を使用することにしました。
これは、私のようなユースケースのように構成ファイルを使用しないことを選択した場合であることを覚えておいてください。
差出人: tony19
いくつかの方法があります:
1) StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext) を使用する
また
2) configuration.debug を「true」に設定して、構成 XML のハードコーディングされた文字列を読み込みます。
static final String LOGBACK_XML =
"<configuration debug='true'>" +
" <appender name='FILE' class='ch.qos.logback.core.RollingFileAppender'>" +
" <file>foo.log</file>" +
" <append>true</append>" +
" <encoder>" +
" <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>" +
" </encoder>" +
" </appender>" +
" <root level='INFO'>" +
" <appender-ref ref='FILE' />" +
" </root>" +
"</configuration>"
;
static public void configLogback() {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
lc.reset();
configurator.doConfigure(new ByteArrayInputStream(LOGBACK_XML.getBytes()));
} catch (JoranException je) {
je.printStackTrace();
}
// you can also print the errors/warning explicitly (instead of debug='true' in xml)
//StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}