Issue Type: Bug Bug
Affects Versions: 1.1.3
Assignee: Logback dev list
Components: logback-classic
Created: 15/Jun/15 10:25 AM
Description:

Logback Manual - Chapter 3: Logback configuration explains configuration using ch.qos.logback.classic.joran.JoranConfigurator but there is no mention about how to use ch.qos.logback.classic.gaffer.GafferConfigurator.
Logback Manual - Chapter 12: Groovy Configuration doesn't mention it either.

I'd expect something along the code snippet below:

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.gaffer.GafferConfigurator;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.status.ErrorStatus;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusManager;
import ch.qos.logback.core.status.StatusUtil;

public static void configureLogging(URL configUrl)
{
	final String GROOVY_EXTENSION = ".groovy";
	ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
	if(loggerFactory instanceof LoggerContext)
	{
		LoggerContext loggerContext = (LoggerContext) loggerFactory;
	
		StatusManager sm = loggerContext.getStatusManager();
		sm.clear();
	
		// reset previous configuration initially loaded from logback.groovy
		loggerContext.reset();
	
		if(configUrl.toString().endsWith(GROOVY_EXTENSION))
		{
			GafferConfigurator configurator = new GafferConfigurator(loggerContext);
			try
			{
				configurator.run(configUrl);
			}
			catch (RuntimeException ex)
			{
				sm.add(new ErrorStatus("Exception while configuring Logback!", configUrl, ex));
			}
		}
		else
		{
			JoranConfigurator configurator = new JoranConfigurator();
			configurator.setContext(loggerContext);
			try
			{
				configurator.doConfigure(configUrl);
			}
			catch (JoranException ex)
			{
				sm.add(new ErrorStatus("Exception while configuring Logback!", configUrl, ex));
			}
		}
	}
}

Another question is whether it would make sense to put this code into a general Configurator that's able to handle both cases.

Project: logback
Labels: configuration groovy
Priority: Major Major
Reporter: Joern Huxhorn
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira