Mixing Java Logging Levels

I set the logging level to CONFIG, but cannot see the messages written at the CONFIG level. What am I missing?

Configuration:

Logger logger = java.util.logging.Logger.getLogger("xxx");
logger.setLevel(java.util.logging.Level.CONFIG);

Tests:

logger.log(java.util.logging.Level.SEVERE, "severe");
logger.log(java.util.logging.Level.WARNING, "warning");
logger.log(java.util.logging.Level.INFO, "info");
logger.log(java.util.logging.Level.CONFIG, "config");
logger.log(java.util.logging.Level.FINE, "fine");
logger.log(java.util.logging.Level.FINER, "finer");
logger.log(java.util.logging.Level.FINEST, "finest");

Conclusion:

SEVERE: severe
WARNING: warning
INFO: info
+3
source share
2 answers

I usually use logback to implement logging, which seems a little better documented. Therefore, I would recommend switching to this.

But to answer your question, I think what happens is that your Loggerset up correctly, but Handlerit sends its messages. The default configuration probably attaches a INFOlayer protocol handler to the root log.

edit: , , . :

for (Handler handler : Logger.getLogger("").getHandlers()) {
    handler.setLevel(Level.CONFIG);
}
logger.config("config");

:

11 2011 . 16:32:14 CONFIG: config

, . , . google .

, :

java.util.logging.ConsoleHandler.level=CONFIG
+7

.

, , , .

:

  • SEVERE ( )
  • INFO
  • CONFIG
  • FINE
  • FINER
  • FINEST ( )

, , INFO, SEVERE, WARNING INFO, CONFIG.


, :

, Logger (log4j, slf4j ..), . , log4j :

  • DEBUG
  • INFO
  • WARN
  • FATAL

CONFIG INFO, .

+1

Source: https://habr.com/ru/post/1791515/


All Articles