|
|||||||||||||||||||
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 | |||||||||||||||
LogKitLoggerStore.java | 100% | 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 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 | 44 |
public LogKitLoggerStore( final LoggerManager loggerManager,
|
41 |
final Logger logger, |
|
42 |
final Context context, |
|
43 |
final Configuration configuration ) |
|
44 |
throws Exception
|
|
45 |
{ |
|
46 | 44 |
if( null == loggerManager ) |
47 |
{ |
|
48 | 1 |
throw new NullPointerException( "loggerManager" ); |
49 |
} |
|
50 | 43 |
m_loggerManager = loggerManager; |
51 |
|
|
52 | 43 |
if( null != logger ) |
53 |
{ |
|
54 | 39 |
ContainerUtil.enableLogging( m_loggerManager, logger ); |
55 |
} |
|
56 |
else
|
|
57 |
{ |
|
58 | 4 |
ContainerUtil.enableLogging( m_loggerManager, new NullLogger() );
|
59 |
} |
|
60 | 43 |
if( null != context ) |
61 |
{ |
|
62 | 1 |
ContainerUtil.contextualize( m_loggerManager, context ); |
63 |
} |
|
64 |
else
|
|
65 |
{ |
|
66 | 42 |
ContainerUtil.contextualize( m_loggerManager, |
67 |
new DefaultContext() );
|
|
68 |
} |
|
69 | 43 |
ContainerUtil.configure( m_loggerManager, configuration ); |
70 | 43 |
setRootLogger( |
71 |
LoggerAlchemist.toDNALogger( m_loggerManager.getDefaultLogger() ) ); |
|
72 |
} |
|
73 |
|
|
74 |
/**
|
|
75 |
* Creates new LogKitLogger for the given category.
|
|
76 |
*/
|
|
77 | 86 |
protected org.jcontainer.dna.Logger createLogger( final String name )
|
78 |
{ |
|
79 | 86 |
return LoggerAlchemist.toDNALogger(
|
80 |
m_loggerManager.getLoggerForCategory( name ) ); |
|
81 |
} |
|
82 |
|
|
83 |
/**
|
|
84 |
* Closes the LoggerStore and shuts down the logger hierarchy.
|
|
85 |
*/
|
|
86 | 43 |
public void close() |
87 |
{ |
|
88 | 43 |
try
|
89 |
{ |
|
90 | 43 |
ContainerUtil.shutdown( m_loggerManager ); |
91 |
} |
|
92 |
catch( Exception e )
|
|
93 |
{ |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
|
|