001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.util;
023:
024: import org.apache.avalon.framework.configuration.Configuration;
025: import org.apache.avalon.framework.configuration.ConfigurationException;
026: import org.apache.avalon.framework.logger.Logger;
027: import org.apache.avalon.framework.logger.Log4JLogger;
028: import org.jacorb.config.LoggerFactory;
029: import java.util.HashMap;
030: import java.util.Map;
031:
032: /**
033: * JacORB logger factory that creates named Avalon loggers with log4j
034: * as the underlying log mechanism.
035: *
036: * @author <a href="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
037: * @version $Revision: 57194 $
038: */
039: public class Log4jLoggerFactory implements LoggerFactory {
040: /** logging back-end mechanism used by all Log4jLoggerFactory instances */
041: private final static String name = "log4j";
042:
043: /** cache of created loggers */
044: private final Map namedLoggers = new HashMap();
045:
046: // Auxiliary static methods --------------------------------------
047:
048: /**
049: * Gets a log4j logger by name.
050: *
051: * @param name the name of the logger
052: * @return an <code>org.apache.log4j.Logger</code> instance
053: */
054: private static org.apache.log4j.Logger getLog4jLogger(String name) {
055: org.jboss.logging.Logger l = org.jboss.logging.Logger
056: .getLogger(name);
057: org.jboss.logging.LoggerPlugin lp = l.getLoggerPlugin();
058: if (lp instanceof org.jboss.logging.Log4jLoggerPlugin)
059: return ((org.jboss.logging.Log4jLoggerPlugin) lp)
060: .getLogger();
061: else
062: return null;
063: }
064:
065: // Implementation of org.apache.avalon.framework.configuration.Configuration
066:
067: public void configure(Configuration configuration)
068: throws ConfigurationException {
069: }
070:
071: // Implementation of org.jacorb.util.LoggerFactory ---------------
072:
073: /**
074: * Gets the name of the logging back-end mechanism.
075: *
076: * @return the string <code>"log4j"</code>
077: */
078: public final String getLoggingBackendName() {
079: return name;
080: }
081:
082: /**
083: * Gets an Avalon logger by name.
084: *
085: * @param name the name of the logger
086: * @return an <code>org.apache.avalon.framework.logger.Logger</code>
087: * instance
088: */
089: public Logger getNamedLogger(String name) {
090: Object o = namedLoggers.get(name);
091:
092: if (o != null)
093: return (Logger) o;
094:
095: org.apache.log4j.Logger log4jLogger = getLog4jLogger(name);
096: Logger logger = new Log4JLogger(log4jLogger);
097:
098: namedLoggers.put(name, logger);
099: return logger;
100: }
101:
102: /**
103: * Gets an Avalon root logger by name.
104: *
105: * @param name the name of the logger
106: * @return an <code>org.apache.avalon.framework.logger.Logger</code>
107: * instance
108: */
109: public Logger getNamedRootLogger(String name) {
110: return getNamedLogger(name);
111: }
112:
113: /**
114: * Creates a named Avalon logger with given <code>logFileName</code>
115: * and <code>maxLogSize</code> parameters. This is a dummy implementation
116: * that always return null.
117: *
118: * @param name the name of the logger
119: * @param logFileName the name of the file to log to
120: * @param maxLogSize maximum size of the log file.
121: *
122: * @return the new logger (null in this implementation).
123: */
124: public Logger getNamedLogger(String name, String logFileName,
125: long maxLogSize) throws java.io.IOException {
126: return null;
127: }
128:
129: /**
130: * set the file name and max file size for logging to a file
131: */
132: public void setDefaultLogFile(String fileName, long maxLogSize)
133: throws java.io.IOException {
134: // not implemented
135: }
136:
137: }
|