Package: JoranLoggerContextConfigurer

JoranLoggerContextConfigurer

nameinstructionbranchcomplexitylinemethod
JoranLoggerContextConfigurer()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
applyConfiguration(LoggingConfiguration, LoggerContext)
M: 13 C: 73
85%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 1 C: 16
94%
M: 0 C: 1
100%
reportFailureIfNecessary(List)
M: 0 C: 15
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2010 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.medic.log.impl.logback;
13:
14: import java.io.StringReader;
15: import java.util.ArrayList;
16: import java.util.List;
17:
18: import org.eclipse.virgo.medic.log.LoggingConfiguration;
19: import org.xml.sax.InputSource;
20:
21: import ch.qos.logback.classic.LoggerContext;
22: import ch.qos.logback.classic.joran.JoranConfigurator;
23: import ch.qos.logback.core.joran.spi.JoranException;
24: import ch.qos.logback.core.status.Status;
25:
26: public final class JoranLoggerContextConfigurer implements LoggerContextConfigurer {
27:
28: public void applyConfiguration(LoggingConfiguration configuration, LoggerContext loggerContext) throws LoggerContextConfigurationFailedException {
29: JoranConfigurator configurator = new JoranConfigurator();
30: configurator.setContext(loggerContext);
31: String configurationString = configuration.getConfiguration();
32: try {
33: configurator.doConfigure(new InputSource(new StringReader(configurationString)));
34: List<Status> statusList = loggerContext.getStatusManager().getCopyOfStatusList();
35: List<String> failureMessages = new ArrayList<String>();
36:• for (Status status : statusList) {
37:• if (Status.INFO != status.getLevel()) {
38: Throwable cause = null;
39: Throwable t = status.getThrowable();
40:• if (t != null) {
41: cause = t.getCause();
42: }
43:• failureMessages.add(status.getMessage() + (cause != null ? " Caused by " + cause + "." : ""));
44: }
45: }
46: reportFailureIfNecessary(failureMessages);
47: } catch (JoranException je) {
48: throw new LoggerContextConfigurationFailedException("Configuration failed", je);
49: }
50: }
51:
52: private static void reportFailureIfNecessary(List<String> failureMessages) throws LoggerContextConfigurationFailedException {
53:• if (!failureMessages.isEmpty()) {
54: throw new LoggerContextConfigurationFailedException("Configuration failed with the following problems: " + failureMessages);
55: }
56: }
57: }