]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.maven/src/main/java/org/argeo/slc/maven/embedder/MavenEmbedderLoggerManager.java
f6202817a5de978e6015e9d7e1b60524185a4a56
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.maven / src / main / java / org / argeo / slc / maven / embedder / MavenEmbedderLoggerManager.java
1 package org.argeo.slc.maven.embedder;
2
3 /*
4 * Copyright 2001-2005 The Apache Software Foundation.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 import org.codehaus.plexus.logging.AbstractLoggerManager;
20 import org.codehaus.plexus.logging.Logger;
21 import org.codehaus.plexus.logging.LoggerManager;
22 import org.codehaus.plexus.logging.console.ConsoleLogger;
23 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
24
25 /**
26 * This is a simple logger manager that will only write the logging statements to the console.
27 * <p/>
28 * Sample configuration:
29 * <pre>
30 * <logging>
31 * <implementation>org.codehaus.plexus.logging.ConsoleLoggerManager</implementation>
32 * <logger>
33 * <threshold>DEBUG</threshold>
34 * </logger>
35 * </logging>
36 * </pre>
37 *
38 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
39 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
40 * @version $Id: MavenEmbedderLoggerManager.java 292888 2005-10-01 01:17:36Z jvanzyl $
41 */
42 public class MavenEmbedderLoggerManager
43 extends AbstractLoggerManager
44 implements LoggerManager, Initializable
45 {
46 /**
47 * Message of this level or higher will be logged.
48 * <p/>
49 * This field is set by the plexus container thus the name is 'threshold'. The field
50 * currentThreshold contains the current setting of the threshold.
51 */
52 private String threshold = "info";
53
54 private int currentThreshold;
55
56 private Logger logger;
57
58 public MavenEmbedderLoggerManager( Logger logger )
59 {
60 this.logger = logger;
61 }
62
63 public void initialize()
64 {
65 debug( "Initializing ConsoleLoggerManager: " + this.hashCode() + "." );
66
67 currentThreshold = parseThreshold( threshold );
68
69 if ( currentThreshold == -1 )
70 {
71 debug( "Could not parse the threshold level: '" + threshold + "', setting to debug." );
72 currentThreshold = Logger.LEVEL_DEBUG;
73 }
74 }
75
76 public void setThreshold( int currentThreshold )
77 {
78 this.currentThreshold = currentThreshold;
79 }
80
81 /**
82 * @return Returns the threshold.
83 */
84 public int getThreshold()
85 {
86 return currentThreshold;
87 }
88
89 public void setThreshold( String role, String roleHint, int threshold )
90 {
91 }
92
93 public int getThreshold( String role, String roleHint )
94 {
95 return currentThreshold;
96 }
97
98 public Logger getLoggerForComponent( String role, String roleHint )
99 {
100 return logger;
101 }
102
103 public void returnComponentLogger( String role, String roleHint )
104 {
105 }
106
107 public int getActiveLoggerCount()
108 {
109 return 1;
110 }
111
112 private int parseThreshold( String text )
113 {
114 text = text.trim().toLowerCase();
115
116 if ( text.equals( "debug" ) )
117 {
118 return ConsoleLogger.LEVEL_DEBUG;
119 }
120 else if ( text.equals( "info" ) )
121 {
122 return ConsoleLogger.LEVEL_INFO;
123 }
124 else if ( text.equals( "warn" ) )
125 {
126 return ConsoleLogger.LEVEL_WARN;
127 }
128 else if ( text.equals( "error" ) )
129 {
130 return ConsoleLogger.LEVEL_ERROR;
131 }
132 else if ( text.equals( "fatal" ) )
133 {
134 return ConsoleLogger.LEVEL_FATAL;
135 }
136
137 return -1;
138 }
139
140 /**
141 * Remove this method and all references when this code is verified.
142 *
143 * @param msg
144 */
145 private void debug( String msg )
146 {
147 }
148 }