How to disable log4j logging from Java code

前端 未结 8 1650
难免孤独
难免孤独 2021-02-07 13:58

I use a legacy library that writes logs using log4j. My default log4j.properties file directs the log to the console, but in some specific functions of my main program, I would

相关标签:
8条回答
  • 2021-02-07 14:48

    For newer log4j versions, you may consider to call:

    LogManager.shutdown();

    Instead of:

    Logger.shutdown();

    which is deprecated. But it still makes the same thing:

    Calling this method will safely close and remove all appenders in all the categories including root contained in the default hierachy.

    0 讨论(0)
  • 2021-02-07 14:50

    In the version 1.8 of java.util.logging.Logger the correctly form is:

    Logger.getLogger("").setLevel(Level.OFF);

    0 讨论(0)
提交回复
热议问题