Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-925

Unattached appenders are started but not stopped

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.0.13
    • logback-core
    • None

    Description

      If an appender like

      public class FooAppender extends AppenderBase<ILoggingEvent>
      {
      	protected void append(ILoggingEvent eventObject)
      	{
      	}
      
      	public void start()
      	{
      		super.start();
      		System.out.println("############################################################");
      		System.out.println("############################################################");
      		System.out.println(""+getName()+" started!");
      		System.out.println("############################################################");
      		System.out.println("############################################################");
      	}
      	
      	public void stop()
      	{
      		super.stop();
      		System.out.println("############################################################");
      		System.out.println("############################################################");
      		System.out.println(""+getName()+" stopped!");
      		System.out.println("############################################################");
      		System.out.println("############################################################");
      	}
      
      }
      

      is defined in a logback.xml but never attached to any logger then

      LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
      loggerContext.reset();
      

      will not execute the stop() call. start(), on the other hand, is executed during configuration.

      There are two possible solutions to this problem: either Logback should detect that the appender is unused and never call start() (I guess this would make the most sense) or reset should also call stop() on unattached appenders.

      While an unattached appender seems like a misconfiguration there are situations where an appender-ref is temporarily removed without even noticing that it was the last use of the appender. An unattached appender should therefore cause a warning but start()/stop() behavior should be consistent even in that case.

      Attachments

        Activity

          People

            logback-dev Logback dev list
            jhuxhorn Joern Huxhorn
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: