How to enable FINE logging for a single java class

前端 未结 5 1217
温柔的废话
温柔的废话 2021-01-21 06:13

I\'m using java.util.logging.Logger logging in my program. How do I enable FINE logging for a single class, while setting it to WARNING for every othe

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-21 06:25

    Well, here's a method I added to my mail class that's actually working. I would still welcome any improvements from others.

    private static void setupLogging() {
      // To enable FINE logging in a single class, apparently this bewildering
      // maze of statements is required.
      Logger.getLogger("").setLevel(Level.FINE);
      for (Handler handler : Logger.getLogger("").getHandlers()) {
        handler.setLevel(Level.FINE);
      }
      MyOtherClass.logger.setLevel(Level.FINE);
      Logger.getLogger("").setLevel(Level.WARNING);
    }
    

提交回复
热议问题