|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Log4JLoggerStore.java | - | 100% | 100% | 100% |
|
1 |
/*
|
|
2 |
* Copyright (C) The Spice Group. All rights reserved.
|
|
3 |
*
|
|
4 |
* This software is published under the terms of the Spice
|
|
5 |
* Software License version 1.1, a copy of which has been included
|
|
6 |
* with this distribution in the LICENSE.txt file.
|
|
7 |
*/
|
|
8 |
package org.codehaus.spice.loggerstore.stores;
|
|
9 |
|
|
10 |
import java.io.InputStream;
|
|
11 |
import java.util.Properties;
|
|
12 |
import org.apache.log4j.LogManager;
|
|
13 |
import org.apache.log4j.PropertyConfigurator;
|
|
14 |
import org.apache.log4j.spi.LoggerRepository;
|
|
15 |
import org.apache.log4j.xml.DOMConfigurator;
|
|
16 |
import org.jcontainer.dna.Logger;
|
|
17 |
import org.jcontainer.dna.impl.Log4JLogger;
|
|
18 |
import org.w3c.dom.Element;
|
|
19 |
|
|
20 |
/**
|
|
21 |
* Log4JLoggerStore extends AbstractLoggerStore to provide the implementation
|
|
22 |
* specific to the Log4J logger.
|
|
23 |
*
|
|
24 |
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
|
|
25 |
*/
|
|
26 |
public class Log4JLoggerStore |
|
27 |
extends AbstractLoggerStore
|
|
28 |
{ |
|
29 |
/** The logger repository */
|
|
30 |
private final LoggerRepository m_repository;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Creates a <code>Log4JLoggerStore</code> using the configuration resource
|
|
34 |
*
|
|
35 |
* @param resource the Element encoding the configuration resource
|
|
36 |
* @throws Exception if fails to create or configure Logger
|
|
37 |
*/
|
|
38 | 4 |
public Log4JLoggerStore( final Element resource )
|
39 |
throws Exception
|
|
40 |
{ |
|
41 | 4 |
LogManager.resetConfiguration(); |
42 | 4 |
m_repository = LogManager.getLoggerRepository(); |
43 | 4 |
final DOMConfigurator configurator = new DOMConfigurator();
|
44 | 4 |
configurator.doConfigure( resource, m_repository ); |
45 | 4 |
setRootLogger( new Log4JLogger( m_repository.getRootLogger() ) );
|
46 |
} |
|
47 |
|
|
48 |
/**
|
|
49 |
* Creates a <code>Log4JLoggerStore</code> using the configuration resource
|
|
50 |
*
|
|
51 |
* @param resource the InputStream encoding the configuration resource
|
|
52 |
* @throws Exception if fails to create or configure Logger
|
|
53 |
*/
|
|
54 | 14 |
public Log4JLoggerStore( final InputStream resource )
|
55 |
throws Exception
|
|
56 |
{ |
|
57 | 14 |
LogManager.resetConfiguration(); |
58 | 14 |
m_repository = LogManager.getLoggerRepository(); |
59 | 14 |
final DOMConfigurator configurator = new DOMConfigurator();
|
60 | 14 |
configurator.doConfigure( resource, m_repository ); |
61 | 14 |
setRootLogger( new Log4JLogger( m_repository.getRootLogger() ) );
|
62 |
} |
|
63 |
|
|
64 |
/**
|
|
65 |
* Creates a <code>Log4JLoggerStore</code> using the configuration resource
|
|
66 |
*
|
|
67 |
* @param resource the Properties encoding the configuration resource
|
|
68 |
* @throws Exception if fails to create or configure Logger
|
|
69 |
*/
|
|
70 | 18 |
public Log4JLoggerStore( final Properties resource )
|
71 |
throws Exception
|
|
72 |
{ |
|
73 | 18 |
LogManager.resetConfiguration(); |
74 | 18 |
m_repository = LogManager.getLoggerRepository(); |
75 | 18 |
final PropertyConfigurator configurator = new PropertyConfigurator();
|
76 | 18 |
configurator.doConfigure( resource, m_repository ); |
77 | 18 |
setRootLogger( new Log4JLogger( m_repository.getRootLogger() ) );
|
78 |
} |
|
79 |
|
|
80 |
/**
|
|
81 |
* Creates new Log4JLogger for the given category.
|
|
82 |
*/
|
|
83 | 72 |
protected Logger createLogger( final String categoryName )
|
84 |
{ |
|
85 | 72 |
return new Log4JLogger( m_repository.getLogger( categoryName ) ); |
86 |
} |
|
87 |
|
|
88 |
/**
|
|
89 |
* Closes the LoggerStore and shuts down the logger hierarchy.
|
|
90 |
*/
|
|
91 | 36 |
public void close() |
92 |
{ |
|
93 | 36 |
m_repository.shutdown(); |
94 |
} |
|
95 |
} |
|
96 |
|
|