2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.maven
.embedder
;
20 * Copyright 2001-2005 The Apache Software Foundation.
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
26 * http://www.apache.org/licenses/LICENSE-2.0
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
35 import org
.codehaus
.plexus
.logging
.AbstractLoggerManager
;
36 import org
.codehaus
.plexus
.logging
.Logger
;
37 import org
.codehaus
.plexus
.logging
.LoggerManager
;
38 import org
.codehaus
.plexus
.logging
.console
.ConsoleLogger
;
39 import org
.codehaus
.plexus
.personality
.plexus
.lifecycle
.phase
.Initializable
;
42 * This is a simple logger manager that will only write the logging statements to the console.
44 * Sample configuration:
47 * <implementation>org.codehaus.plexus.logging.ConsoleLoggerManager</implementation>
49 * <threshold>DEBUG</threshold>
54 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
55 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
56 * @version $Id: MavenEmbedderLoggerManager.java 292888 2005-10-01 01:17:36Z jvanzyl $
58 public class MavenEmbedderLoggerManager
59 extends AbstractLoggerManager
60 implements LoggerManager
, Initializable
63 * Message of this level or higher will be logged.
65 * This field is set by the plexus container thus the name is 'threshold'. The field
66 * currentThreshold contains the current setting of the threshold.
68 private String threshold
= "info";
70 private int currentThreshold
;
72 private Logger logger
;
74 public MavenEmbedderLoggerManager( Logger logger
)
79 public void initialize()
81 debug( "Initializing ConsoleLoggerManager: " + this.hashCode() + "." );
83 currentThreshold
= parseThreshold( threshold
);
85 if ( currentThreshold
== -1 )
87 debug( "Could not parse the threshold level: '" + threshold
+ "', setting to debug." );
88 currentThreshold
= Logger
.LEVEL_DEBUG
;
92 public void setThreshold( int currentThreshold
)
94 this.currentThreshold
= currentThreshold
;
98 * @return Returns the threshold.
100 public int getThreshold()
102 return currentThreshold
;
105 public void setThreshold( String role
, String roleHint
, int threshold
)
109 public int getThreshold( String role
, String roleHint
)
111 return currentThreshold
;
114 public Logger
getLoggerForComponent( String role
, String roleHint
)
119 public void returnComponentLogger( String role
, String roleHint
)
123 public int getActiveLoggerCount()
128 private int parseThreshold( String text
)
130 text
= text
.trim().toLowerCase();
132 if ( text
.equals( "debug" ) )
134 return ConsoleLogger
.LEVEL_DEBUG
;
136 else if ( text
.equals( "info" ) )
138 return ConsoleLogger
.LEVEL_INFO
;
140 else if ( text
.equals( "warn" ) )
142 return ConsoleLogger
.LEVEL_WARN
;
144 else if ( text
.equals( "error" ) )
146 return ConsoleLogger
.LEVEL_ERROR
;
148 else if ( text
.equals( "fatal" ) )
150 return ConsoleLogger
.LEVEL_FATAL
;
157 * Remove this method and all references when this code is verified.
161 private void debug( String msg
)