001: package org.apache.maven.embedder;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: /*
023: * Licensed to the Apache Software Foundation (ASF) under one
024: * or more contributor license agreements. See the NOTICE file
025: * distributed with this work for additional information
026: * regarding copyright ownership. The ASF licenses this file
027: * to you under the Apache License, Version 2.0 (the
028: * "License"); you may not use this file except in compliance
029: * with the License. You may obtain a copy of the License at
030: *
031: * http://www.apache.org/licenses/LICENSE-2.0
032: *
033: * Unless required by applicable law or agreed to in writing,
034: * software distributed under the License is distributed on an
035: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
036: * KIND, either express or implied. See the License for the
037: * specific language governing permissions and limitations
038: * under the License.
039: */
040:
041: import org.codehaus.plexus.logging.AbstractLoggerManager;
042: import org.codehaus.plexus.logging.Logger;
043: import org.codehaus.plexus.logging.LoggerManager;
044: import org.codehaus.plexus.logging.console.ConsoleLogger;
045: import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
046:
047: /**
048: * This is a simple logger manager that will only write the logging statements to the console.
049: * <p/>
050: * Sample configuration:
051: * <pre>
052: * <logging>
053: * <implementation>org.codehaus.plexus.logging.ConsoleLoggerManager</implementation>
054: * <logger>
055: * <threshold>DEBUG</threshold>
056: * </logger>
057: * </logging>
058: * </pre>
059: *
060: * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
061: * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
062: * @version $Id: MavenEmbedderLoggerManager.java 513028 2007-02-28 22:50:21Z jvanzyl $
063: */
064: public class MavenEmbedderLoggerManager extends AbstractLoggerManager
065: implements LoggerManager, Initializable {
066: /**
067: * Message of this level or higher will be logged.
068: * <p/>
069: * This field is set by the plexus container thus the name is 'threshold'. The field
070: * currentThreshold contains the current setting of the threshold.
071: */
072: private String threshold = "info";
073:
074: private int currentThreshold;
075:
076: private Logger logger;
077:
078: public MavenEmbedderLoggerManager(Logger logger) {
079: this .logger = logger;
080: }
081:
082: public void initialize() {
083: debug("Initializing ConsoleLoggerManager: " + this .hashCode()
084: + ".");
085:
086: currentThreshold = parseThreshold(threshold);
087:
088: if (currentThreshold == -1) {
089: debug("Could not parse the threshold level: '" + threshold
090: + "', setting to debug.");
091: currentThreshold = Logger.LEVEL_DEBUG;
092: }
093: }
094:
095: public void setThreshold(int currentThreshold) {
096: this .currentThreshold = currentThreshold;
097: }
098:
099: public void setThresholds(int currentThreshold) {
100: this .currentThreshold = currentThreshold;
101:
102: logger.setThreshold(currentThreshold);
103: }
104:
105: /** @return Returns the threshold. */
106: public int getThreshold() {
107: return currentThreshold;
108: }
109:
110: public void setThreshold(String role, String roleHint, int threshold) {
111: }
112:
113: public int getThreshold(String role, String roleHint) {
114: return currentThreshold;
115: }
116:
117: public Logger getLoggerForComponent(String role, String roleHint) {
118: return logger;
119: }
120:
121: public void returnComponentLogger(String role, String roleHint) {
122: }
123:
124: public int getActiveLoggerCount() {
125: return 1;
126: }
127:
128: private int parseThreshold(String text) {
129: text = text.trim().toLowerCase();
130:
131: if (text.equals("debug")) {
132: return ConsoleLogger.LEVEL_DEBUG;
133: } else if (text.equals("info")) {
134: return ConsoleLogger.LEVEL_INFO;
135: } else if (text.equals("warn")) {
136: return ConsoleLogger.LEVEL_WARN;
137: } else if (text.equals("error")) {
138: return ConsoleLogger.LEVEL_ERROR;
139: } else if (text.equals("fatal")) {
140: return ConsoleLogger.LEVEL_FATAL;
141: }
142:
143: return -1;
144: }
145:
146: /**
147: * Remove this method and all references when this code is verified.
148: *
149: * @param msg
150: */
151: private void debug(String msg) {
152: }
153: }
|