What do SLF4J 2.0's own startup lines, such as 'Actual provider is of type [...]', tell you, and what does slf4j.internal.verbosity change?
answer
- SLF4J reports on its own binding
- level prefixes on stderr
- first provider in the list wins
- default verbosity is INFO
- errors cannot be silenced
basics
~10 sSLF4J prints its own SLF4J(I)/SLF4J(W) lines to stderr about binding: no provider, several providers, and 'Actual provider is of type', naming the winner. slf4j.internal.verbosity (default INFO) filters those lines, never application logs.
solid answer
~40 sSince 2.0.10, SLF4J reports on its own startup through an internal reporter that is independent of the backend: lines prefixed `SLF4J(D):`, `SLF4J(I):`, `SLF4J(W):` or `SLF4J(E):`, written to stderr by default. With several providers it warns `Class path contains multiple SLF4J providers.`, lists each one, and then prints `Actual provider is of type [...]` at INFO, naming the first provider `ServiceLoader` returned, which is the one bound. With none it warns `No SLF4J providers were found.`; with exactly one it prints only a DEBUG line. `slf4j.internal.verbosity` sets the threshold: default `INFO`, `DEBUG` from 2.0.16, `WARN` hides the INFO lines, `ERROR` hides warnings, and errors always print. It does not change application log levels.
code
console · 5 linesSLF4J(W): Class path contains multiple SLF4J providers.
SLF4J(W): Found provider [org.slf4j.simple.SimpleServiceProvider@1b6d3586]
SLF4J(W): Found provider [org.slf4j.nop.NOPServiceProvider@4554617c]
SLF4J(W): See https://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J(I): Actual provider is of type [org.slf4j.simple.SimpleServiceProvider@1b6d3586]go deeper
Recall the SLF4J(W) and SLF4J(I) prefixes, that the lines go to stderr, and that 'Actual provider is of type' names the backend that won.
Explain the levels: the single-provider line is DEBUG, the multiple-provider lines are WARN plus one INFO, and errors cannot be silenced.
Use these lines first when logs look wrong after a dependency change, and know which verbosity setting would have hidden the evidence.
Decide whether builds should treat any SLF4J(W) line at startup as a release blocker rather than leaving it for someone to read.
## SLF4J talks about itself, separately from your logs **SLF4J** is the logging API your code calls; a separate **provider** (a backend such as `slf4j-simple`, reload4j through `slf4j-reload4j`, Logback or Log4j 2) does the real writing. While it starts up, SLF4J needs to tell you things about the binding itself, before any backend exists to write them. It does this through an internal class, `org.slf4j.helpers.Reporter` (added in 2.0.10), whose javadoc notes that the system is **independent of the logging back-end in use**. - Every internal message carries a prefix showing its level: `SLF4J(D): `, `SLF4J(I): `, `SLF4J(W): ` and `SLF4J(E): ` for debug, info, warn and error. - The lines go to **standard error** by default. The system property `slf4j.internal.report.stream` can send them to standard output instead, with the values `System.out`, `stdout` or `sysout`. - Because they bypass the backend, they never appear in your log files or follow your backend's format. You read them on the console or wherever the process's stderr is captured. ## The lines you will actually meet | Situation at startup | What SLF4J 2.0.20 prints | Level | |---|---|---| | exactly one provider | `Connected with provider of type [org.slf4j.simple.SimpleServiceProvider]` | DEBUG, hidden by default | | several providers | `Class path contains multiple SLF4J providers.`, a `Found provider [...]` line for each, a link to the explanation | WARN | | several providers, after binding | `Actual provider is of type [...]` | INFO | | no provider | `No SLF4J providers were found.`, `Defaulting to no-operation (NOP) logger implementation`, a link | WARN | The most useful one in an interview is **`Actual provider is of type [...]`**. When `ServiceLoader` returns several providers, `LoggerFactory` binds to the **first one in the list** and prints which one that was. The order follows the class path, so the winner can change when dependency order changes. That line answers the question "which backend am I actually running on?". ```console SLF4J(W): Class path contains multiple SLF4J providers. SLF4J(W): Found provider [org.slf4j.simple.SimpleServiceProvider@1b6d3586] SLF4J(W): Found provider [org.slf4j.nop.NOPServiceProvider@4554617c] SLF4J(W): See https://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J(I): Actual provider is of type [org.slf4j.simple.SimpleServiceProvider@1b6d3586] ``` The `@...` suffix is the object's default `toString()`; the class name before it is what matters. A healthy start with one provider prints **nothing** at the default settings, because its only line is DEBUG. ## What slf4j.internal.verbosity changes The system property **`slf4j.internal.verbosity`** sets how chatty SLF4J's internal reporter is. It never touches your application's log levels, which belong to the backend's configuration. 1. **Default is `INFO`**: INFO, WARN and ERROR lines print; DEBUG lines do not. 2. **`DEBUG`** (2.0.16 and later) also prints debug lines such as `Connected with provider of type [...]`, handy to confirm which provider a single-provider start chose. 3. **`WARN`** hides INFO lines, so `Actual provider is of type [...]` and the `slf4j.provider` "Attempting to load" line disappear, while the multiple-provider and no-provider warnings remain. 4. **`ERROR`** hides warnings too, including `No SLF4J providers were found.`. 5. **ERROR-level lines are always printed**: the reporter's error methods cannot be disabled. Any value it does not recognise is treated as `INFO`. The setting is read once when the reporter class loads, so pass it as a JVM option: `-Dslf4j.internal.verbosity=DEBUG`. ## When the lines appear SLF4J initializes **lazily**. Nothing is printed until the first `LoggerFactory.getLogger(...)` call, which is usually a static logger field in the first class that logs. The `SLF4J(...)` lines therefore show up at that moment, often before the backend's own first output, and only once for each loaded copy of `slf4j-api`. If you see them in the middle of a startup log, that is simply the point at which the first logger was created, not a second initialization. ## How a junior should use this - After adding or changing a logging dependency, start the application once and read the `SLF4J(...)` lines on stderr. - If you see `multiple SLF4J providers`, read `Actual provider is of type` to learn which backend won, then remove the one you did not want. - If you see `No SLF4J providers were found.`, nothing will be logged at all until a provider is added. - Never "fix" the warnings by setting the verbosity to `ERROR`: that hides the evidence and leaves the problem in place.
- A service's SLF4J startup lines never show up in its log files. Is something broken?No. SLF4J's internal reporter writes straight to standard error, or to standard output if `slf4j.internal.report.stream` says so, without passing through the backend. That is deliberate: it has to work before, or without, any backend. Look wherever the process's stderr is captured.
- How do you confirm which provider a single-provider service is bound to, when nothing is printed?Start it once with `-Dslf4j.internal.verbosity=DEBUG` on 2.0.16 or later. SLF4J then prints `Connected with provider of type [...]` with the provider's class name, the DEBUG line a normal start hides.
- SLF4J's startup lines are written through the backend's appenders.
- slf4j.internal.verbosity sets the application's root log level.
- With two providers, SLF4J refuses to bind and logs nothing.
- Setting verbosity to ERROR is a fine fix for the multiple-provider warning.
- A clean start with one provider always prints which provider it chose.
Assumes slf4j-api 2.0.20; the prefixed internal reporter and slf4j.internal.verbosity arrived in 2.0.10 and its DEBUG level in 2.0.16.