Questions tagged [slf4j]

Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction layer for various logging frameworks. Please also include a tag for the actual logging framework you're using if you are attempting to configure logging for your application.

The Simple Logging Facade for Java (commonly known as "SLF4J") serves as a simple facade or abstraction layer for various logging frameworks, e.g. java.util.logging, log4j and logback.

One can unify all logging across an application and the libraries it uses via this abstraction layer. Code familiar with SLF4J uses the SLF4J API directly for logging. Any existing code or libraries that use some other logging framework can be bridged to get their logging redirected to SLF4J instead. The end application at deployment time includes a binding to the actual logging framework that they are using, and can configure that logging framework as desired for all logging throughout the application.

References:

3285 questions
933
votes
38 answers

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"

My application is to be deployed on both tcServer and WebSphere 6.1. This application uses ehCache and so requires slf4j as a dependency. As a result I've added the slf4j-api.jar (1.6) jar to my war file bundle. The application works fine in…
DJ180
  • 18,724
  • 21
  • 66
  • 117
435
votes
6 answers

Why not use java.util.logging?

For the first time in my life I find myself in a position where I'm writing a Java API that will be open sourced. Hopefully to be included in many other projects. For logging I (and indeed the people I work with) have always used JUL…
peterh
  • 18,404
  • 12
  • 87
  • 115
317
votes
3 answers

How to log formatted message, object array, exception?

What is the correct approach to log both a populated message and a stack trace of the exception? logger.error( "\ncontext info one two three: {} {} {}\n", new Object[] {"1", "2", "3"}, new Exception("something went wrong")); I'd like to…
rowe
  • 3,171
  • 2
  • 15
  • 4
299
votes
21 answers

SLF4J: Class path contains multiple SLF4J bindings

I'm getting the following error. It seems there are multiple logging frameworks bound to slf4j. Not sure how to resolve this. Any help is greatly appreciated. SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in…
user1493140
  • 5,976
  • 4
  • 29
  • 49
211
votes
5 answers

How to configure slf4j-simple

api 1.7 and slf4j-simple as implementation. I just can't find how to configure the logging level with this combination. Can anyone help out?
Gelin Luo
  • 14,035
  • 27
  • 86
  • 139
199
votes
4 answers

Configuring Log4j Loggers Programmatically

I am trying to use SLF4J (with log4j binding) for the first time. I would like to configure 3 different named Loggers that can be returned by a LoggerFactory which will log different levels and push the messages to different appenders: Logger 1…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
194
votes
7 answers

How to use MDC with thread pools?

In our software we extensively use MDC to track things like session IDs and user names for web requests. This works fine while running in the original thread. However, there's a lot of things that need to be processed in the background. For that we…
Lóránt Pintér
  • 10,152
  • 14
  • 47
  • 53
184
votes
2 answers

Is it worth to use slf4j with log4j2

I am not able to decide whether to use slf4j or not with log4j2. Based on online posts, does not look like it will have any performance hit but is it really required. Also these points rule in favor of log4j2: SLF4J forces your application to log…
Andy897
  • 6,915
  • 11
  • 51
  • 86
172
votes
3 answers

Logback to log different messages to two files

I am using logback/slf4j to do my logging. I want to parse my log file to analyze some data, so instead of parsing a great big file (mostly consisting of debug statements) I want to have two logger instances which each log to a separate file; one…
Aly
  • 15,865
  • 47
  • 119
  • 191
172
votes
37 answers

Building with Lombok's @Slf4j and Intellij: Cannot find symbol log

I have a maven project that builds with no problems from the command line. However, when I build it with IntelliJ, I get the error: java: FileName.java:89: cannot find symbol symbol : variable log There is no log defined or imported in the java…
user1991839
  • 1,993
  • 2
  • 14
  • 11
154
votes
5 answers

Best practices for using Markers in SLF4J/Logback

We are using SLF4J+Logback combination at our project for a while now and are quite happy with it, but our logging strategy is fairly simple, using straightforward class based loggers and no fancy stuff like MDC or Markers. What I want to know is if…
Roland Tepp
  • 8,301
  • 11
  • 55
  • 73
150
votes
1 answer

What are markers in Java Logging frameworks and what is a reason to use them?

The first time I heard about markers was while reading: http://slf4j.org/faq.html I checked available methods for the Logger…
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
140
votes
10 answers

How to intercept SLF4J (with logback) logging via a JUnit test?

Is it possible to somehow intercept the logging (SLF4J + logback) and get an InputStream (or something else that is readable) via a JUnit test case...?
carlspring
  • 31,231
  • 29
  • 115
  • 197
137
votes
7 answers

Logger slf4j advantages of formatting with {} instead of string concatenation

Is there any advantage of using {} instead of string concatenation? An example from slf4j logger.debug("Temperature set to {}. Old temperature was {}.", t, oldT); instead of logger.debug("Temperature set to"+ t + ". Old temperature was " +…
Hernán Eche
  • 6,529
  • 12
  • 51
  • 76
131
votes
18 answers

Setting log level of message at runtime 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…
Edward Dale
  • 29,597
  • 13
  • 90
  • 129
1
2 3
99 100