[logback-dev] [JIRA] Commented: (LBCLASSIC-273) Status messages of StatusManager are not cleared upon call to LoggerContext.reset()

Joern Huxhorn (JIRA) noreply-jira at qos.ch
Thu Jun 9 15:40:51 CEST 2011


    [ http://jira.qos.ch/browse/LBCLASSIC-273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12029#action_12029 ] 

Joern Huxhorn commented on LBCLASSIC-273:
-----------------------------------------

Hi Ceki.

The confusing thing happened in our own code.

We have a servlet can trigger a reconfiguration of the Logback environment during runtime.

The code is looking like this:
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(loggerContext);
loggerContext.reset();
StatusManager sm = loggerContext.getStatusManager();
sm.clear();
try
{
	configurator.doConfigure(file);
}
catch(JoranException e)
{
	e.printStackTrace();
}

int level = sm.getLevel();
if(level > Status.INFO)
{
	System.err.println("##### Some problems occurred while configuring Logback using '"+file.getAbsolutePath()+"'! #####");
}
else
{
	System.err.println("Logback configuration refreshed without issues.");
}

if(debug || level > Status.INFO)
{
	List<Status> statusList = sm.getCopyOfStatusList();
	if(statusList != null)
	{
		System.err.println("############################################################");
		System.err.println("## Logback Status                                         ##");
		System.err.println("############################################################");
		StringBuilder statusBuilder=new StringBuilder();
		for(Status current : statusList)
		{
			appendStatus(statusBuilder, current, 0);
		}
		System.err.println(statusBuilder.toString());
		System.err.println("############################################################");
	}
}

(it was previously missing the clear() call on StatusManager which is now a partial workaround for this issue.)

A co-worker of mine wasted a whole lot of time because he tried to find a mistake in the logging configuration that he actually fixed already. But the errors and the corresponding warning did still show up.

The method getLevel() is part of the public interface StatusManager and after checking out http://logback.qos.ch/apidocs/ch/qos/logback/core/status/StatusManager.html I was absolutely sure that the level property would be reset by the clear() call.

The same is the case for http://logback.qos.ch/apidocs/ch/qos/logback/classic/LoggerContext.html#reset() . "This method clears all internal properties" led me to expect that the status messages of the previous configuration would be purged.

This believe was so strong, actually, that I also evaluated the logging configuration of my co-worker after I re-checked our reconfiguration code and the documentation.
I was simply 100% convinced that the problem must be located in the configuration instead of Logback.

And, yes, it was a rather big "D'oh!" effect when I found the root of the problem. ;)

On a side note:
I print the status messages manually since the automatic printing will end up on System.out.
See my comment at http://jira.qos.ch/browse/LBCLASSIC-58?focusedCommentId=10640#action_10640 
We also needed the ability to print them regardless of warn and error by setting debug to true so I would have needed the manual printing anyway.

> Status messages of StatusManager are not cleared upon call to LoggerContext.reset()
> -----------------------------------------------------------------------------------
>
>                 Key: LBCLASSIC-273
>                 URL: http://jira.qos.ch/browse/LBCLASSIC-273
>             Project: logback-classic
>          Issue Type: Bug
>    Affects Versions: 0.9.28
>            Reporter: Joern Huxhorn
>            Assignee: Logback dev list
>
> See https://github.com/ceki/logback/pull/15

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list