1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.geronimo.kernel.log;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.log4j.ConsoleAppender;
22 import org.apache.log4j.Level;
23 import org.apache.log4j.Logger;
24 import org.apache.log4j.PatternLayout;
25
26 /**
27 * Bootstrap log implementation for use with Log4j.
28 *
29 * @version $Rev: 438786 $ $Date: 2006-08-30 21:35:25 -0700 (Wed, 30 Aug 2006) $
30 */
31 public class BootstrapLog4jLog implements Log {
32 static {
33 if (GeronimoLogging.isBootstrapLoggingInitializationEnabled()) {
34 Logger root = Logger.getRootLogger();
35 root.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n")));
36
37 GeronimoLogging level = GeronimoLogging.getDefaultLevel();
38 if (level == null) {
39 root.setLevel(Level.ERROR);
40 } else if (level == GeronimoLogging.TRACE) {
41 root.setLevel(Level.DEBUG);
42 } else if (level == GeronimoLogging.DEBUG) {
43 root.setLevel(Level.DEBUG);
44 } else if (level == GeronimoLogging.INFO) {
45 root.setLevel(Level.INFO);
46 } else if (level == GeronimoLogging.WARN) {
47 root.setLevel(Level.WARN);
48 } else if (level == GeronimoLogging.ERROR) {
49 root.setLevel(Level.ERROR);
50 } else if (level == GeronimoLogging.FATAL) {
51 root.setLevel(Level.FATAL);
52 }
53 }
54 }
55
56 private static final String FQCN = BootstrapLog4jLog.class.getName();
57 private Logger logger;
58
59 public BootstrapLog4jLog(String name) {
60 logger = Logger.getLogger(name);
61 }
62
63 public boolean isTraceEnabled() {
64 return logger.isEnabledFor(Level.DEBUG);
65 }
66
67 public void trace(Object message) {
68 logger.log(FQCN, Level.DEBUG, message, null);
69 }
70
71 public void trace(Object message, Throwable throwable) {
72 logger.log(FQCN, Level.DEBUG, message, throwable);
73 }
74
75 public boolean isDebugEnabled() {
76 return logger.isEnabledFor(Level.DEBUG);
77 }
78
79 public void debug(Object message) {
80 logger.log(FQCN, Level.DEBUG, message, null);
81 }
82
83 public void debug(Object message, Throwable throwable) {
84 logger.log(FQCN, Level.DEBUG, message, throwable);
85 }
86
87 public boolean isInfoEnabled() {
88 return logger.isEnabledFor(Level.INFO);
89 }
90
91 public void info(Object message) {
92 logger.log(FQCN, Level.INFO, message, null);
93 }
94
95 public void info(Object message, Throwable throwable) {
96 logger.log(FQCN, Level.INFO, message, throwable);
97 }
98
99 public boolean isWarnEnabled() {
100 return logger.isEnabledFor(Level.WARN);
101 }
102
103 public void warn(Object message) {
104 logger.log(FQCN, Level.WARN, message, null);
105 }
106
107 public void warn(Object message, Throwable throwable) {
108 logger.log(FQCN, Level.WARN, message, throwable);
109 }
110
111 public boolean isErrorEnabled() {
112 return logger.isEnabledFor(Level.ERROR);
113 }
114
115 public void error(Object message) {
116 logger.log(FQCN, Level.ERROR, message, null);
117 }
118
119 public void error(Object message, Throwable throwable) {
120 logger.log(FQCN, Level.ERROR, message, throwable);
121 }
122
123 public boolean isFatalEnabled() {
124 return logger.isEnabledFor(Level.FATAL);
125 }
126
127 public void fatal(Object message) {
128 logger.log(FQCN, Level.FATAL, message, null);
129 }
130
131 public void fatal(Object message, Throwable throwable) {
132 logger.log(FQCN, Level.FATAL, message, throwable);
133 }
134 }