]> 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
Add license headers
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.maven / src / main / java / org / argeo / slc / maven / embedder / MavenEmbedderLoggerManager.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package org.argeo.slc.maven.embedder;
18
19 /*
20 * Copyright 2001-2005 The Apache Software Foundation.
21 *
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
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
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.
33 */
34
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;
40
41 /**
42 * This is a simple logger manager that will only write the logging statements to the console.
43 * <p/>
44 * Sample configuration:
45 * <pre>
46 * <logging>
47 * <implementation>org.codehaus.plexus.logging.ConsoleLoggerManager</implementation>
48 * <logger>
49 * <threshold>DEBUG</threshold>
50 * </logger>
51 * </logging>
52 * </pre>
53 *
54 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
55 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
56 * @version $Id: MavenEmbedderLoggerManager.java 292888 2005-10-01 01:17:36Z jvanzyl $
57 */
58 public class MavenEmbedderLoggerManager
59 extends AbstractLoggerManager
60 implements LoggerManager, Initializable
61 {
62 /**
63 * Message of this level or higher will be logged.
64 * <p/>
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.
67 */
68 private String threshold = "info";
69
70 private int currentThreshold;
71
72 private Logger logger;
73
74 public MavenEmbedderLoggerManager( Logger logger )
75 {
76 this.logger = logger;
77 }
78
79 public void initialize()
80 {
81 debug( "Initializing ConsoleLoggerManager: " + this.hashCode() + "." );
82
83 currentThreshold = parseThreshold( threshold );
84
85 if ( currentThreshold == -1 )
86 {
87 debug( "Could not parse the threshold level: '" + threshold + "', setting to debug." );
88 currentThreshold = Logger.LEVEL_DEBUG;
89 }
90 }
91
92 public void setThreshold( int currentThreshold )
93 {
94 this.currentThreshold = currentThreshold;
95 }
96
97 /**
98 * @return Returns the threshold.
99 */
100 public int getThreshold()
101 {
102 return currentThreshold;
103 }
104
105 public void setThreshold( String role, String roleHint, int threshold )
106 {
107 }
108
109 public int getThreshold( String role, String roleHint )
110 {
111 return currentThreshold;
112 }
113
114 public Logger getLoggerForComponent( String role, String roleHint )
115 {
116 return logger;
117 }
118
119 public void returnComponentLogger( String role, String roleHint )
120 {
121 }
122
123 public int getActiveLoggerCount()
124 {
125 return 1;
126 }
127
128 private int parseThreshold( String text )
129 {
130 text = text.trim().toLowerCase();
131
132 if ( text.equals( "debug" ) )
133 {
134 return ConsoleLogger.LEVEL_DEBUG;
135 }
136 else if ( text.equals( "info" ) )
137 {
138 return ConsoleLogger.LEVEL_INFO;
139 }
140 else if ( text.equals( "warn" ) )
141 {
142 return ConsoleLogger.LEVEL_WARN;
143 }
144 else if ( text.equals( "error" ) )
145 {
146 return ConsoleLogger.LEVEL_ERROR;
147 }
148 else if ( text.equals( "fatal" ) )
149 {
150 return ConsoleLogger.LEVEL_FATAL;
151 }
152
153 return -1;
154 }
155
156 /**
157 * Remove this method and all references when this code is verified.
158 *
159 * @param msg
160 */
161 private void debug( String msg )
162 {
163 }
164 }