Change global setting for Logger instances

前端 未结 5 902
小蘑菇
小蘑菇 2020-11-30 01:54

I\'m using java.util.logging.Logger as the logging engine for my application. Each class uses it\'s own logger, i.e., each class has:

private final Logger lo         


        
5条回答
  •  忘掉有多难
    2020-11-30 02:11

    JUL(java.util.logging) is java default logger within jvm.

    Java Logging Technology--see Overview

    So you may find that there is a default config file already in C:\Program Files\Java\jre1.8.0_221\lib\logging.properties

    I recommend that you create a new config file under your project to override the default setting, do as following:

    config file name, logging.properties, all log level can be found in Class Level

    handlers= java.util.logging.ConsoleHandler
    .level= INFO
    java.util.logging.ConsoleHandler.level = ALL
    java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
    java.util.logging.SimpleFormatter.format= [%1$tF %1$tT] [%4$-7s] %5$s %n
    
    # your specific logger level
    com.xyz.foo.level = SEVERE
    

    Then add jvm option to enable the config

    java -Djava.util.logging.config.file="logging.properties" -Duser.country=CN -Duser.language=en
    

    user.country and user.language may have an effect on log message localization

提交回复
热议问题