001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.lib.log;
020:
021: import org.apache.log4j.Level;
022: import org.apache.log4j.LogManager;
023: import org.apache.log4j.Logger;
024:
025: /**
026: * {@link LogFactory} implementation that delegates to the Log4J framework.
027: *
028: * @author Patrick Linskey
029: */
030: public class Log4JLogFactory extends LogFactoryAdapter {
031:
032: protected Log newLogAdapter(String channel) {
033: return new LogAdapter((Logger) LogManager.getLogger(channel));
034: }
035:
036: /**
037: * Adapts a Log4J logger to the {@link org.apache.openjpa.lib.log.Log} interface.
038: */
039: public static class LogAdapter implements Log {
040:
041: private Logger _log;
042:
043: private LogAdapter(Logger wrapee) {
044: _log = wrapee;
045: }
046:
047: public Logger getDelegate() {
048: return _log;
049: }
050:
051: public boolean isTraceEnabled() {
052: return _log.isEnabledFor(Level.DEBUG);
053: }
054:
055: public boolean isInfoEnabled() {
056: return _log.isEnabledFor(Level.INFO);
057: }
058:
059: public boolean isWarnEnabled() {
060: return _log.isEnabledFor(Level.WARN);
061: }
062:
063: public boolean isErrorEnabled() {
064: return _log.isEnabledFor(Level.ERROR);
065: }
066:
067: public boolean isFatalEnabled() {
068: return _log.isEnabledFor(Level.FATAL);
069: }
070:
071: public void trace(Object o) {
072: _log.debug(o);
073: }
074:
075: public void trace(Object o, Throwable t) {
076: _log.debug(o, t);
077: }
078:
079: public void info(Object o) {
080: _log.info(o);
081: }
082:
083: public void info(Object o, Throwable t) {
084: _log.info(o, t);
085: }
086:
087: public void warn(Object o) {
088: _log.warn(o);
089: }
090:
091: public void warn(Object o, Throwable t) {
092: _log.warn(o, t);
093: }
094:
095: public void error(Object o) {
096: _log.error(o);
097: }
098:
099: public void error(Object o, Throwable t) {
100: _log.error(o, t);
101: }
102:
103: public void fatal(Object o) {
104: _log.fatal(o);
105: }
106:
107: public void fatal(Object o, Throwable t) {
108: _log.fatal(o, t);
109: }
110: }
111: }
|