View Javadoc
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 public Log4JLoggerStore( final Element resource ) 39 throws Exception 40 { 41 LogManager.resetConfiguration(); 42 m_repository = LogManager.getLoggerRepository(); 43 final DOMConfigurator configurator = new DOMConfigurator(); 44 configurator.doConfigure( resource, m_repository ); 45 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 public Log4JLoggerStore( final InputStream resource ) 55 throws Exception 56 { 57 LogManager.resetConfiguration(); 58 m_repository = LogManager.getLoggerRepository(); 59 final DOMConfigurator configurator = new DOMConfigurator(); 60 configurator.doConfigure( resource, m_repository ); 61 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 public Log4JLoggerStore( final Properties resource ) 71 throws Exception 72 { 73 LogManager.resetConfiguration(); 74 m_repository = LogManager.getLoggerRepository(); 75 final PropertyConfigurator configurator = new PropertyConfigurator(); 76 configurator.doConfigure( resource, m_repository ); 77 setRootLogger( new Log4JLogger( m_repository.getRootLogger() ) ); 78 } 79 80 /*** 81 * Creates new Log4JLogger for the given category. 82 */ 83 protected Logger createLogger( final String categoryName ) 84 { 85 return new Log4JLogger( m_repository.getLogger( categoryName ) ); 86 } 87 88 /*** 89 * Closes the LoggerStore and shuts down the logger hierarchy. 90 */ 91 public void close() 92 { 93 m_repository.shutdown(); 94 } 95 }

This page was automatically generated by Maven