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 org.apache.avalon.excalibur.logger.LoggerManager;
11 import org.apache.avalon.framework.configuration.Configuration;
12 import org.apache.avalon.framework.container.ContainerUtil;
13 import org.apache.avalon.framework.context.Context;
14 import org.apache.avalon.framework.context.DefaultContext;
15 import org.apache.avalon.framework.logger.Logger;
16 import org.apache.avalon.framework.logger.NullLogger;
17 import org.jcomponent.alchemist.LoggerAlchemist;
18
19 /***
20 * <p>LogKitLoggerStore extends AbstractLoggerStore to provide the
21 * implementation specific to the LogKit logger. </p>
22 *
23 * @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
24 */
25 public class LogKitLoggerStore
26 extends AbstractLoggerStore
27 {
28 /*** The Logger Manager */
29 private final LoggerManager m_loggerManager;
30
31 /***
32 * Creates a <code>LogKitLoggerStore</code> using the given configuration
33 *
34 * @param loggerManager the LoggerManager used to configure the store
35 * @param logger the Logger to logEnable the LoggerManager
36 * @param context the Context of the LoggerManager
37 * @param configuration the logger configuration
38 * @throws Exception if fails to create or configure Logger
39 */
40 public LogKitLoggerStore( final LoggerManager loggerManager,
41 final Logger logger,
42 final Context context,
43 final Configuration configuration )
44 throws Exception
45 {
46 if( null == loggerManager )
47 {
48 throw new NullPointerException( "loggerManager" );
49 }
50 m_loggerManager = loggerManager;
51
52 if( null != logger )
53 {
54 ContainerUtil.enableLogging( m_loggerManager, logger );
55 }
56 else
57 {
58 ContainerUtil.enableLogging( m_loggerManager, new NullLogger() );
59 }
60 if( null != context )
61 {
62 ContainerUtil.contextualize( m_loggerManager, context );
63 }
64 else
65 {
66 ContainerUtil.contextualize( m_loggerManager,
67 new DefaultContext() );
68 }
69 ContainerUtil.configure( m_loggerManager, configuration );
70 setRootLogger(
71 LoggerAlchemist.toDNALogger( m_loggerManager.getDefaultLogger() ) );
72 }
73
74 /***
75 * Creates new LogKitLogger for the given category.
76 */
77 protected org.jcontainer.dna.Logger createLogger( final String name )
78 {
79 return LoggerAlchemist.toDNALogger(
80 m_loggerManager.getLoggerForCategory( name ) );
81 }
82
83 /***
84 * Closes the LoggerStore and shuts down the logger hierarchy.
85 */
86 public void close()
87 {
88 try
89 {
90 ContainerUtil.shutdown( m_loggerManager );
91 }
92 catch( Exception e )
93 {
94 }
95 }
96 }
This page was automatically generated by Maven