001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.geronimo.kernel.log;
019
020 import java.lang.reflect.Method;
021 import java.util.Map;
022 import java.util.HashMap;
023
024 import org.apache.commons.logging.LogFactory;
025
026 /**
027 * @version $Rev: 513482 $ $Date: 2007-03-01 15:19:42 -0500 (Thu, 01 Mar 2007) $
028 */
029 public class GeronimoLogging {
030
031 //this needs to go before the instance constants or you get an NPE in the constructor.
032 private static final Map levels = new HashMap();
033
034 public static final GeronimoLogging TRACE = new GeronimoLogging("TRACE");
035 public static final GeronimoLogging DEBUG = new GeronimoLogging("DEBUG");
036 public static final GeronimoLogging INFO = new GeronimoLogging("INFO");
037 public static final GeronimoLogging WARN = new GeronimoLogging("WARN");
038 public static final GeronimoLogging ERROR = new GeronimoLogging("ERROR");
039 public static final GeronimoLogging FATAL = new GeronimoLogging("FATAL");
040
041 private static boolean initialized = false;
042 private static GeronimoLogging consoleLogLevel = ERROR;
043 private static GeronimoLogging defaultLevel;
044
045 /**
046 * Initializes the logging system used by Geronimo. This MUST be called in
047 * in the main class used to start the geronimo server.
048 */
049 public static void initialize(GeronimoLogging level) {
050 if (!initialized) {
051 defaultLevel = level;
052 consoleLogLevel = level;
053
054 // force the log factory to initialize
055 LogFactory.getLog(GeronimoLogging.class);
056
057 initialized = true;
058 }
059 }
060
061 public static void setDefaultLogLevel(GeronimoLogging level) {
062 defaultLevel = level;
063 }
064
065 public static GeronimoLogging getDefaultLevel() {
066 return defaultLevel;
067 }
068
069 public static GeronimoLogging getConsoleLogLevel() {
070 return consoleLogLevel;
071 }
072
073 public static void setConsoleLogLevel(GeronimoLogging consoleLogLevel) {
074 GeronimoLogging.consoleLogLevel = consoleLogLevel;
075 }
076
077 public static GeronimoLogging getGeronimoLogging(String level) {
078 return (GeronimoLogging) levels.get(level);
079 }
080
081 private final String level;
082
083 private GeronimoLogging(String level) {
084 this.level = level;
085 levels.put(level, this);
086 }
087
088 public String toString() {
089 return level;
090 }
091
092 /**
093 * Check if the Geronimo bootstrap logging initialization is enabled.
094 *
095 * <p>Checks the system property <tt>geronimo.bootstrap.logging.enabled</tt>
096 * if not set, or set to "true" then bootstrap logging initialization is enabled.
097 *
098 * @return True of bootstrap logging initialization is enabled.
099 */
100 public static boolean isBootstrapLoggingInitializationEnabled() {
101 String value = System.getProperty("geronimo.bootstrap.logging.enabled");
102 if (value == null) {
103 return true;
104 }
105 else {
106 return Boolean.valueOf(value).booleanValue();
107 }
108 }
109 }