In a framework setting it is very difficult to predict when the logging will be initialized since you often don't control main.
Besides the framework may want to actually switch from a NOP (or Simple Logger) while it is initializing to a full blown LogFactory.getLogger() after the bootstrap process has finished (You could do with with the SubstituteLogger to retain events IIRC). It is also actually fairly difficult to unit test logging code since you really don't control the bootstrap process especially since many tests like Spring framework require a special JUnit runner (@RunWith). > That's why I still don't really understand what you're trying to achieve. I'm trying to recommend a pattern for libraries that want to do some logging perhaps only for diagnostic and development purposes but logging is not a critical component of the library (perhaps even the logging is too opaque anyway for normal users). Particularly if this library is high performance or maybe used by android applications. In such case the library would default to the NOPLogger and thus not initialize. The reality is 99% of libraries that do logging is completely irrelevant to the consumer of the library. The logging is mostly trace. In a environment like Android this adds up to be nontrivial amount of performance loss (as well as callstack and method count issues). Finally as another person alluded there is also a chicken and egg problem If I'm trying to bootstrap my application to get ready to configure logging and perhaps use a parsing library (json, yaml whatever) or configuration library and that library uses logging... we now have a problem. Of course you could standardize this in SLF4J with perhaps some sort two phase approach but then you complicate SLF4J. Also after looking at 20 of our various log4j.xml/logback.xml/log4j2.xml config code bases the only loggers we care about are our own and maybe the parent framework (Spring). Thats it. On Sat, Mar 18, 2017 at 11:52 AM, Joachim Durchholz <[email protected]> wrote: > Am 17.03.2017 um 16:51 schrieb Adam Gent: >> >> Many library writers want to use SLF4j but may want to avoid the >> default initialization and binding process. > > > Actually that is the decision of the main program to make. > Libraries should simply send their log messages to SLF4J and let it report > or ignore them. > > That's why I still don't really understand what you're trying to achieve. > _______________________________________________ > slf4j-user mailing list > [email protected] > http://mailman.qos.ch/mailman/listinfo/slf4j-user -- CTO SnapHop (snaphop.com) (twitter) @agentgt (linkedin) http://www.linkedin.com/in/agentgt (cell) 781-883-5182 _______________________________________________ slf4j-user mailing list [email protected] http://mailman.qos.ch/mailman/listinfo/slf4j-user
