[slf4j-user] Recommendation for library writers: use thiscopy and paste wrapper around SLF4j to avoid default static initialization

Joachim Durchholz jo at durchholz.org
Sun Mar 19 01:56:19 CET 2017


Am 18.03.2017 um 22:37 schrieb Adam Gent:
> But the chicken/egg problem is real albeit solvable particularly with
> more powerful logging backends.

I am not aware of any chicken/egg problems here.

The course of events is (roughly; in particular, I'm skipping 
configuration because I forgot whether that's before or after backend 
initialization):
- SLF4J initializes its API so it can accept logging calls.
- SLF4J starts initializing backend machinery.
   - Backend machinery emits log messages to SLF4J.
     - SLF4J knows it is in a sort-of recursive call,
       so it knows it does not have a backend yet
       and simply stores the message in a list.
   - Backend machinery is done initializing,
     return to SLF4J's initialization routine.
- SLF4J checks if backend machinery initialization failed;
   if yes:
   - SLF4J outputs the messages from the list to stderr.
   if no:
   - SLF4J feeds the messages from the list to the backend.

There would be a chicken-and-egg problem if SLF4J tried to use the 
backend before it is initialized. But that does not happen.



More information about the slf4j-user mailing list