[Bug 201] New: Need ability to shutdown loggers and flush appenders

http://bugzilla.slf4j.org/show_bug.cgi?id=201 Summary: Need ability to shutdown loggers and flush appenders Product: SLF4J Version: 1.6.x Platform: PC OS/Version: Windows NT Status: NEW Severity: enhancement Priority: P1 Component: Core API AssignedTo: slf4j-dev@qos.ch ReportedBy: mike.schall@gmail.com There needs to be a way to shutdown logging and flush async appenders so when a process is closing, all log events are written before the process is closed. Should ILoggerFactory have a shutdown or stop method? It could shutdown whatever logging back end I'm using? For log4j it would call - org.apache.log4j.LogManager.getLoggerRepository().shutdown(); For logback it would call - loggerContext.stop() Other back ends - ??? This is required to allow me to not reference logging back ends explicitly in my code to shutdown successfully without losing events. Discussion about this is happening on the user list at - http://www.qos.ch/pipermail/logback-user/2010-September/001816.html -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 Ceki Gulcu <listid@qos.ch> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |WONTFIX --- Comment #1 from Ceki Gulcu <listid@qos.ch> 2010-10-13 19:08:02 --- Adding a shutdown or stop method to ILoggerFactory would be out of SLF4J's scope. -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 Ondrej Zizka <zizka@seznam.cz> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |zizka@seznam.cz Status|RESOLVED |REOPENED Resolution|WONTFIX | --- Comment #2 from Ondrej Zizka <zizka@seznam.cz> 2010-12-23 17:10:51 --- I also need this feature. I don't think it's out of SLF4J's scope. Where is that scope defined please? -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 Ondrej Zizka <zizka@seznam.cz> changed: What |Removed |Added ---------------------------------------------------------------------------- OS/Version|Windows NT |All Platform|PC |All -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 --- Comment #3 from Ondrej Zizka <zizka@seznam.cz> 2010-12-23 17:28:36 --- Actually, I need a flush() method. Should I file a new bugzilla? -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 Robert Elliot <robert@teviotia.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |robert@teviotia.co.uk --- Comment #4 from Robert Elliot <robert@teviotia.co.uk> 2010-12-23 17:34:05 --- It's not my decision, but I think that basically the thinking is that if you are in a position where it's appropriate to shut the logging system down or flush all events in the logging system then you ought to know what the logging system is, so you can do it directly on the logging system. SLF4J is meant to be an interface for retrieving loggers and logging to them - the bare minimum of shared functionality. I don't think it's meant to be trying to abstract all possible things you might want to do with any given logging system. -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 --- Comment #5 from Michael Schall <mike.schall@gmail.com> 2010-12-23 20:42:48 --- (In reply to comment #4)
It's not my decision, but I think that basically the thinking is that if you are in a position where it's appropriate to shut the logging system down or flush all events in the logging system then you ought to know what the logging system is, so you can do it directly on the logging system.
SLF4J is meant to be an interface for retrieving loggers and logging to them - the bare minimum of shared functionality. I don't think it's meant to be trying to abstract all possible things you might want to do with any given logging system.
I would suggest that if SLF4J knows enough to configure logging, it could know enough to shutdown logging. -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 --- Comment #6 from Robert Elliot <robert@teviotia.co.uk> 2010-12-23 21:48:03 ---
I would suggest that if SLF4J knows enough to configure logging, it could know enough to shutdown logging.
True. However, SLF4J doesn't know enough to configure logging. You configure Logback or Log4J or JULI or whatever directly, not via SLF4J. -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 Gili <cowwoc@bbs.darktech.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |cowwoc@bbs.darktech.org --- Comment #7 from Gili <cowwoc@bbs.darktech.org> --- +1 for needing flush(), ideally in slf4j. My use-case is needing to log a bunch of errors, then throw an exception. The logger output is going to stdout, the exception stack-trace to stderr, so the combined output ends up getting interleaved (making it hard to read). Ideally, I'd like to flush the log before throwing the exception. -- You are receiving this mail because: You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 --- Comment #8 from Robert Elliot <robert@teviotia.co.uk> --- This use case seems to me an excellent example of why shutdown/flush should *not* be in SLF4J. It's characteristics are as follows: 1) It is explicitly about application lifecycle, specifically about how an application stops. As such it's perfectly reasonable for the code that starts and stops the application (and hence *must* depend directly on a specific SLF4J implementation) to know about that implementation and use it. Logback, for instance, has a means to shut it down - this can simply be used in the context of application ending code. 2) It is explicitly about *how* log messages are handled (in this case, sent to standard out). One of the basic ideas about SLF4J is that it knows nothing about what happens to a log message and its arguments. They may be discarded, they may be sent over a socket to some other process, they may be sent to a database, they may be held in memory - that's all the business of the implementation and its configuration, *not* SLF4J. To me a great deal of the value and flexibility of the SLF4J interface lies in how little it attempts to abstract over. It does not seek to abstract over an entire logging implementation, only over the basics of sending a log message to something unknown that may do what it likes with it. The primary use case to me is libraries, that do not know what application will bring them in or what logging implementation it may be interested in or how it may seek to output its log statements. That's all a different concern. -- You are receiving this mail because: You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 --- Comment #9 from Gili <cowwoc@bbs.darktech.org> --- Start by implementing it in Logback (or pointing out how to do it if it's already implemented). My own take is that there is nothing controversial in asking slf4j to expose functionality that are available on all known loggers. The question is whether all loggers already do so. -- You are receiving this mail because: You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 --- Comment #10 from Robert Elliot <robert@teviotia.co.uk> --- import org.slf4j.LoggerFactory; import ch.qos.logback.classic.LoggerContext; ((LoggerContext) LoggerFactory.getILoggerFactory()).stop(); The last thing I want is a library that depends only on SLF4J being able to stop logging because its writer wrongly supposed that application that brings it in would ever want to log after that point. It's the same error that leads libraries to try and set logger levels or (worse!) configure their own appenders. SLF4J is not an abstraction across all things a logging system might want to do, it is particularly an abstraction over the concern of sending messages to a logging system. The fact that it doesn't expose an API to do those other things is a strength - I know that if I bring in a library that depends only on SLF4J it won't do anything dumb. -- You are receiving this mail because: You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 --- Comment #11 from Gili <cowwoc@bbs.darktech.org> --- I think there is a misunderstanding. I'm talking about flushing a logger, not shutting it down. If this functionally is added then I don't see the need for a shutdown mechanism. Flushing is a safe operation. -- You are receiving this mail because: You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 sean <sean@thescottasylum.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |sean@thescottasylum.com --- Comment #12 from sean <sean@thescottasylum.com> --- I agree. SLF4J ( with logback ) does not require any code dependencies to the underlying logging framework. The factory provides logger instances that implement SLF4J interfaces. Why be belligerent about the request to put a shutdown interface into the API (Even suggesting its a feature)? If you would add the method/interface, the implementation of the logger can do what they want with the interface, and the user of SLF4J (me) can invoke it at the proper time in the application lifecycle. What you are suggesting eliminates the value of having logger agnostic API to code to. I mean really? get the underlying logger, cast it to an implementation, and then use it? If I am building a code dependency on the underlying logger, why even use SLF4J? Come on guys. -- You are receiving this mail because: You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 Chetan Mehrotra <chetan.mehrotra@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |chetan.mehrotra@gmail.com --- Comment #13 from Chetan Mehrotra <chetan.mehrotra@gmail.com> --- Another option can be that if the ILoggerFactory implementation also implements the Closeable interface [1]. Then client code need not depend on specific API but can be generic import org.slf4j.LoggerFactory; if(LoggerFactory.getILoggerFactory() implements Closeable){ ((Closeable)LoggerFactory.getILoggerFactory()).close(); } Thus if any of the bindings require cleanup then there respetive factories implement the Closeable interface e.g. Logback [1] http://docs.oracle.com/javase/7/docs/api/java/io/Closeable.html -- You are receiving this mail because: You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 --- Comment #14 from Chetan Mehrotra <chetan.mehrotra@gmail.com> --- I meant using instanceof instead of implements. Looks like bugzilla does not allow editing comments -- You are receiving this mail because: You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 Alexander <iamfuric@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |iamfuric@gmail.com --- Comment #15 from Alexander <iamfuric@gmail.com> --- I totally agree with Sean. Casting to underlying implementation is not an option if SLF4J stands for *FACADE*. And if slf4j somehow bootstraps the underlying library, it should at least provide API to gracefully shut it down. -- You are receiving this mail because: You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 Börcsök József <borcsokj@sch.bme.hu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |borcsokj@sch.bme.hu --- Comment #16 from Börcsök József <borcsokj@sch.bme.hu> --- I agree with the comments below, SLF2J should provide and API to forward shutting down event to the underlying implementations. My project depends on slf4j-api only, my sources don't know what the logger implementation is, deployer users can package it with their favorite one (JAR and configuration files). Can you tell me what version will contain this feature? -- You are receiving this mail because: You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=201 Nico Schlebusch <nico@slash.co.za> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |nico@slash.co.za -- You are receiving this mail because: You are the assignee for the bug.
participants (2)
-
bugzilla-daemon@pixie.qos.ch
-
bugzilla-daemon@qos.ch