Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slf4j logging with jdk – how to enable debug?

By default slf4j, when using with jdk (slf4j-jdk14-1.6.1.jar), does not log debug messages. How do I enable them?

I can’t find info neither in the official docs, the web or here on how to enable it.

I found some info on (failed though) creating a file in %JDK_HOME%/lib and defining the level there, in a config file. However, I would like to define the level at compile-/run-time so I can both run and debug my app from my IDE with different logging levels.

Isn’t there some environment variable I can set, or VM arg?

like image 293
Kissaki Avatar asked Nov 25 '10 15:11

Kissaki


People also ask

How do I enable debugging in logger?

If it is specific to a certain application, then the application logger can be set to DEBUG. Steps: 1) Go to System Configuration -> Platform Configuration -> Logging . 2) Select Action -> Manage Appenders.

How do I enable debug logs in spring boot?

You can enable debug logging by specifying --debug when starting the application from the command-line. Spring Boot provides also a nice starting point for logback to configure some defaults, coloring etc. the base. xml file which you can simply include in your logback.


2 Answers

Why do you think it does not log DEBUG messages?

If you mean that your log.debug(String) logging calls do not end up in java.util.logging log files, then I guess you have to configure the logging.properties configuration file to allow log messages at FINE level.

If you do not want to mess with the global %JRE_HOME%/lib/logging.properties, then you can just pass in -Djava.util.logging.config.file=logging.properties on the command line - this will force the logging system to look for that configuration file in the current directory.

Or use some other (programmatic) way to configure java.util.logging, see below for tutorial.

This has nothing to do with configuring SLF4J; in fact, SLF4J does not have any configuration, everything is configured by simply swapping JAR files.


For your reference:

  • JDK14LoggerAdapter
  • Java Logging API tutorial
like image 198
Neeme Praks Avatar answered Sep 22 '22 11:09

Neeme Praks


If you are using slf4j SimpleLogger implementation read this.

There you can see that simpleLogger use INFO as default log level. You can change it by using a system property. This is usefull for non-production evironments:

static {      System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace"); } 
like image 37
KingQuercus Avatar answered Sep 18 '22 11:09

KingQuercus