Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable debug in slf4j Logger?

How to globally enable debug for all the slf4j.Logger objects?

like image 388
missingfaktor Avatar asked Jun 01 '12 09:06

missingfaktor


People also ask

How do I enable debugging in logger?

You need to set the logger level to the lowest you want to display. For example, if you want to display DEBUG messages, you need to set the logger level to DEBUG. The Apache log4j manual has a section on Configuration. Show activity on this post.

What is debug mode in logger?

debug . This combination of a configurable logging level and logging statements within your program allow you full control over how your application will log its activity.

How do you change the log level in slf4j?

When using log4j, the Logger. log(Priority p, Object message) method is available and can be used to log a message at a log level determined at runtime. We're using this fact and this tip to redirect stderr to a logger at a specific log level. slf4j doesn't have a generic log() method that I can find.

Is slf4j same as log4j?

Comparison SLF4J and Log4j Unlike log4j, SLF4J (Simple Logging Facade for Java) is not an implementation of logging framework, it is an abstraction for all those logging frameworks in Java similar to log4J. Therefore, you cannot compare both.


2 Answers

Programmatically, with logback:

setLoggingLevel(ch.qos.logback.classic.Level.DEBUG); 

where

public static void setLoggingLevel(ch.qos.logback.classic.Level level) {     ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);     root.setLevel(level); } 
like image 92
assylias Avatar answered Sep 19 '22 11:09

assylias


exists various capability to switch debug log on:
this article have good explanation all of those. to me good fit is:

Using slf4j with Log4j logger
create file src/main/resources/log4j.properties

log4j.rootLogger=DEBUG, STDOUT log4j.logger.deng=INFO log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n 
like image 37
madjardi Avatar answered Sep 19 '22 11:09

madjardi