2017-03-07 22 views
0

実際には、ログ設定を確認するためにリスナーが必要です。 リスナーはすべてのロガークラスをチェックし、設定を変更する場合は許可しません。リスナーを使用してロガーの設定を確認するにはどうすればよいですか?

ありがとう

+0

は、実行時にlogback設定ファイルを設定する方法[のhttp://stackoverflow.com/questions/30939814/how-to-set-logback-configuration-file-at-runtime – freedev

+2

可能な重複の重複している可能性があり?](http://stackoverflow.com/questions/30939814/how-to-set-logback-configuration-file-at-runtime) –

答えて

0

このpart of documentationは、実行時に設定をロードする方法について説明します。 logback.xmlファイルをjarまたはwarに埋め込み、リソースとしてロードするには、次の例を見てください。

InputStream is = YourClass.class.getResourceAsStream("embedded-logback-log.xml"); 

LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); 

try { 
    JoranConfigurator configurator = new JoranConfigurator(); 
    configurator.setContext(context); 
    // Call context.reset() to clear any previous configuration, e.g. default 
    // configuration. For multi-step configuration, omit calling context.reset(). 
    context.reset(); 

    // Here you load the new configuration 
    configurator.doConfigure(is); 

} catch (JoranException je) { 
    // StatusPrinter will handle this 
} 
StatusPrinter.printInCaseOfErrorsOrWarnings(context); 

logger.info("Entering application."); 
+0

JoranConfiguratorを使用していただきありがとうございます。「情報」レベルでログインするように強制クラスを設定することはできますか? –

+0

変更ログレベルが "情報"または必要なものであれば、新しい構成をロード(または作成)できます。 – freedev

+0

ありがとう、私は私の質問を変更しました。自分のログ設定を継続的にチェックするためにリスナーが必要です。 –

関連する問題