All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.groupbyinc.common.apache.commons.logging.impl.LogKitLogger Maven / Gradle / Ivy

There is a newer version: 198
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.logging.impl;

import java.io.Serializable;
import org.apache.log.Logger;
import org.apache.log.Hierarchy;
import org.apache.commons.logging.Log;

/**
 * Implementation of org.apache.commons.logging.Log
 * that wraps the avalon-logkit
 * logging system. Configuration of LogKit is left to the user.
 * 

* LogKit accepts only String messages. * Therefore, this implementation converts object messages into strings * by called their toString() method before logging them. * * @version $Id: LogKitLogger.java 1448119 2013-02-20 12:28:04Z tn $ */ public class LogKitLogger implements Log, Serializable { /** Serializable version identifier. */ private static final long serialVersionUID = 3768538055836059519L; // ------------------------------------------------------------- Attributes /** Logging goes to this LogKit logger */ protected transient volatile Logger logger = null; /** Name of this logger */ protected String name = null; // ------------------------------------------------------------ Constructor /** * Construct LogKitLogger which wraps the LogKit * logger with given name. * * @param name log name */ public LogKitLogger(String name) { this.name = name; this.logger = getLogger(); } // --------------------------------------------------------- Public Methods /** * Return the underlying Logger we are using. */ public Logger getLogger() { Logger result = logger; if (result == null) { synchronized(this) { result = logger; if (result == null) { logger = result = Hierarchy.getDefaultHierarchy().getLoggerFor(name); } } } return result; } // ----------------------------------------------------- Log Implementation /** * Logs a message with org.apache.log.Priority.DEBUG. * * @param message to log * @see org.apache.commons.logging.Log#trace(Object) */ public void trace(Object message) { debug(message); } /** * Logs a message with org.apache.log.Priority.DEBUG. * * @param message to log * @param t log this cause * @see org.apache.commons.logging.Log#trace(Object, Throwable) */ public void trace(Object message, Throwable t) { debug(message, t); } /** * Logs a message with org.apache.log.Priority.DEBUG. * * @param message to log * @see org.apache.commons.logging.Log#debug(Object) */ public void debug(Object message) { if (message != null) { getLogger().debug(String.valueOf(message)); } } /** * Logs a message with org.apache.log.Priority.DEBUG. * * @param message to log * @param t log this cause * @see org.apache.commons.logging.Log#debug(Object, Throwable) */ public void debug(Object message, Throwable t) { if (message != null) { getLogger().debug(String.valueOf(message), t); } } /** * Logs a message with org.apache.log.Priority.INFO. * * @param message to log * @see org.apache.commons.logging.Log#info(Object) */ public void info(Object message) { if (message != null) { getLogger().info(String.valueOf(message)); } } /** * Logs a message with org.apache.log.Priority.INFO. * * @param message to log * @param t log this cause * @see org.apache.commons.logging.Log#info(Object, Throwable) */ public void info(Object message, Throwable t) { if (message != null) { getLogger().info(String.valueOf(message), t); } } /** * Logs a message with org.apache.log.Priority.WARN. * * @param message to log * @see org.apache.commons.logging.Log#warn(Object) */ public void warn(Object message) { if (message != null) { getLogger().warn(String.valueOf(message)); } } /** * Logs a message with org.apache.log.Priority.WARN. * * @param message to log * @param t log this cause * @see org.apache.commons.logging.Log#warn(Object, Throwable) */ public void warn(Object message, Throwable t) { if (message != null) { getLogger().warn(String.valueOf(message), t); } } /** * Logs a message with org.apache.log.Priority.ERROR. * * @param message to log * @see org.apache.commons.logging.Log#error(Object) */ public void error(Object message) { if (message != null) { getLogger().error(String.valueOf(message)); } } /** * Logs a message with org.apache.log.Priority.ERROR. * * @param message to log * @param t log this cause * @see org.apache.commons.logging.Log#error(Object, Throwable) */ public void error(Object message, Throwable t) { if (message != null) { getLogger().error(String.valueOf(message), t); } } /** * Logs a message with org.apache.log.Priority.FATAL_ERROR. * * @param message to log * @see org.apache.commons.logging.Log#fatal(Object) */ public void fatal(Object message) { if (message != null) { getLogger().fatalError(String.valueOf(message)); } } /** * Logs a message with org.apache.log.Priority.FATAL_ERROR. * * @param message to log * @param t log this cause * @see org.apache.commons.logging.Log#fatal(Object, Throwable) */ public void fatal(Object message, Throwable t) { if (message != null) { getLogger().fatalError(String.valueOf(message), t); } } /** * Checks whether the LogKit logger will log messages of priority DEBUG. */ public boolean isDebugEnabled() { return getLogger().isDebugEnabled(); } /** * Checks whether the LogKit logger will log messages of priority ERROR. */ public boolean isErrorEnabled() { return getLogger().isErrorEnabled(); } /** * Checks whether the LogKit logger will log messages of priority FATAL_ERROR. */ public boolean isFatalEnabled() { return getLogger().isFatalErrorEnabled(); } /** * Checks whether the LogKit logger will log messages of priority INFO. */ public boolean isInfoEnabled() { return getLogger().isInfoEnabled(); } /** * Checks whether the LogKit logger will log messages of priority DEBUG. */ public boolean isTraceEnabled() { return getLogger().isDebugEnabled(); } /** * Checks whether the LogKit logger will log messages of priority WARN. */ public boolean isWarnEnabled() { return getLogger().isWarnEnabled(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy