📄 log.java
字号:
/**
* Copyright (c) 2005, Paul Tuckey
* All rights reserved.
*
* Each copy or derived work must preserve the copyright notice and this
* notice unmodified.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
package org.tuckey.web.filters.urlrewrite.utils;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
/**
* Log copies the style of commons logging. The only reason this exists is that many problems
* were had with Log4j and commons-logging interfering with peoples installed configuration.
* It is very easy to change this to log4j or commons-logging by settting log level to "log4j" or "commons"
* Note, this will fall back to system.log if not initialised with a context.
*
* @author Paul Tuckey
* @version $Revision: 1.8 $ $Date: 2005/12/07 10:27:00 $
*/
public class Log {
private static Log localLog = Log.getLog(Log.class);
// static vars
private static ServletContext context = null;
private static final String DEFAULT_LOG_LEVEL = "INFO";
private static boolean usingSystemOut = false;
private static boolean usingSystemErr = false;
private static boolean usingLog4j = false;
private static boolean usingCommonsLogging = false;
private static boolean traceLevelEnabled = false;
private static boolean debugLevelEnabled = false;
private static boolean infoLevelEnabled = false;
private static boolean warnLevelEnabled = false;
private static boolean errorLevelEnabled = false;
private static boolean fatalLevelEnabled = false;
private Class clazz = null;
private org.apache.log4j.Logger log4jLogger = null;
private org.apache.commons.logging.Log commonsLog = null;
private Log(Class clazz) {
this.clazz = clazz;
// check for log4j or commons
isUsingLog4j();
isUsingCommonsLogging();
}
private boolean isUsingLog4j() {
if (usingLog4j && log4jLogger == null) {
this.log4jLogger = org.apache.log4j.Logger.getLogger(clazz);
}
return usingLog4j;
}
public boolean isUsingCommonsLogging() {
if (usingCommonsLogging && commonsLog == null) {
this.commonsLog = org.apache.commons.logging.LogFactory.getLog(clazz);
}
return usingCommonsLogging;
}
public boolean isTraceEnabled() {
if (isUsingLog4j()) return log4jLogger.isEnabledFor(org.apache.log4j.Priority.DEBUG);
if (isUsingCommonsLogging()) return commonsLog.isTraceEnabled();
return traceLevelEnabled;
}
public boolean isDebugEnabled() {
if (isUsingLog4j()) return log4jLogger.isEnabledFor(org.apache.log4j.Priority.DEBUG);
if (isUsingCommonsLogging()) return commonsLog.isDebugEnabled();
if (traceLevelEnabled) return true;
return debugLevelEnabled;
}
public boolean isInfoEnabled() {
if (isUsingLog4j()) return log4jLogger.isEnabledFor(org.apache.log4j.Priority.INFO);
if (isUsingCommonsLogging()) return commonsLog.isInfoEnabled();
if (traceLevelEnabled) return true;
if (debugLevelEnabled) return true;
return infoLevelEnabled;
}
public boolean isWarnEnabled() {
if (isUsingLog4j()) return log4jLogger.isEnabledFor(org.apache.log4j.Priority.WARN);
if (isUsingCommonsLogging()) return commonsLog.isWarnEnabled();
if (traceLevelEnabled) return true;
if (debugLevelEnabled) return true;
if (infoLevelEnabled) return true;
return warnLevelEnabled;
}
public boolean isErrorEnabled() {
if (isUsingLog4j()) return log4jLogger.isEnabledFor(org.apache.log4j.Priority.ERROR);
if (isUsingCommonsLogging()) return commonsLog.isErrorEnabled();
if (traceLevelEnabled) return true;
if (debugLevelEnabled) return true;
if (infoLevelEnabled) return true;
if (warnLevelEnabled) return true;
return errorLevelEnabled;
}
public boolean isFatalEnabled() {
if (isUsingLog4j()) return log4jLogger.isEnabledFor(org.apache.log4j.Priority.FATAL);
if (isUsingCommonsLogging()) return commonsLog.isFatalEnabled();
if (traceLevelEnabled) return true;
if (debugLevelEnabled) return true;
if (infoLevelEnabled) return true;
if (warnLevelEnabled) return true;
if (errorLevelEnabled) return true;
return fatalLevelEnabled;
}
public void trace(Object o) {
if (!isTraceEnabled()) {
return;
}
if (isUsingLog4j()) {
log4jLogger.debug(o);
return;
}
if (isUsingCommonsLogging()) {
commonsLog.trace(o);
return;
}
write("TRACE", o);
}
public void trace(Object o, Throwable throwable) {
if (!isTraceEnabled()) {
return;
}
if (isUsingLog4j()) {
log4jLogger.debug(o, throwable);
return;
}
if (isUsingCommonsLogging()) {
commonsLog.trace(o, throwable);
return;
}
write("TRACE", o, throwable);
}
public void trace(Throwable throwable) {
if (!isTraceEnabled()) {
return;
}
if (isUsingLog4j()) {
log4jLogger.debug(throwable);
return;
}
if (isUsingCommonsLogging()) {
commonsLog.trace(throwable);
return;
}
write("TRACE", throwable, throwable);
}
public void debug(Object o) {
if (!isDebugEnabled()) {
return;
}
if (isUsingLog4j()) {
log4jLogger.debug(o);
return;
}
if (isUsingCommonsLogging()) {
commonsLog.debug(o);
return;
}
write("DEBUG", o);
}
public void debug(Object o, Throwable throwable) {
if (!isDebugEnabled()) {
return;
}
if (isUsingLog4j()) {
log4jLogger.debug(o, throwable);
return;
}
if (isUsingCommonsLogging()) {
commonsLog.debug(o, throwable);
return;
}
write("DEBUG", o, throwable);
}
public void debug(Throwable throwable) {
if (!isDebugEnabled()) {
return;
}
if (isUsingLog4j()) {
log4jLogger.debug(throwable);
return;
}
if (isUsingCommonsLogging()) {
commonsLog.debug(throwable);
return;
}
write("DEBUG", throwable, throwable);
}
public void info(Object o) {
if (!isInfoEnabled()) {
return;
}
if (isUsingLog4j()) {
log4jLogger.info(o);
return;
}
if (isUsingCommonsLogging()) {
commonsLog.info(o);
return;
}
write("INFO", o);
}
public void info(Object o, Throwable throwable) {
if (!isInfoEnabled()) {
return;
}
if (isUsingLog4j()) {
log4jLogger.info(o, throwable);
return;
}
if (isUsingCommonsLogging()) {
commonsLog.info(o, throwable);
return;
}
write("INFO", o, throwable);
}
public void info(Throwable throwable) {
if (!isInfoEnabled()) {
return;
}
if (isUsingLog4j()) {
log4jLogger.info(throwable);
return;
}
if (isUsingCommonsLogging()) {
commonsLog.info(throwable);
return;
}
write("INFO", throwable, throwable);
}
public void warn(Object o) {
if (!isWarnEnabled()) {
return;
}
if (isUsingLog4j()) {
log4jLogger.warn(o);
return;
}
if (isUsingCommonsLogging()) {
commonsLog.warn(o);
return;
}
write("WARN", o);
}
public void warn(Object o, Throwable throwable) {
if (!isWarnEnabled()) {
return;
}
if (isUsingLog4j()) {
log4jLogger.warn(o, throwable);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -