📄 logger.java
字号:
/**
Copyright (C) 2002-2003 Together
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Logger.java
Date: 02.12.2003.
@version 1.0.0
@authors:
Milosevic Sinisa sinisa@prozone.co.yu
Radoslav Dutina rale@prozone.co.yu
Zoran Milakovic zoran@prozone.co.yu
*/
package org.webdocwf.util.loader.logging;
import java.io.IOException;
/**
* A general-purpose logging facility. It is modeled after
* <CODE>syslogd</CODE>. This is a base class from which an actual
* implementation is derived. It only defines how log message are written
* by a client. Where the log message is written and the mechanism for
* controlling logging is left up to the implementation. This class does
* not define any of these mechanism and their definition is not necessary
* for understand how to use this class. <P>
*
* Each log message is associate with a facility and has a level assigned
* to it. A facility is a symbolic (String) name that defines a class of
* log messages. A level is used to indicate the
*
It is expected that the implementation can enable, disable and
* direct log messages based on these attributes. Facilities and levels
* are defined symbolicly, with no restriction on the name, and form a tuple.
* Several standard levels are defined as integer constants and their use
* is expected to be higher performing than symbolic levels..<P>
*
*
*Normally, a single,
global instance of the object
* is exists and is obtainable by a static method in this class.<P>
*
* Log messages are written via an object implementing <CODE>LogChannel</CODE>.
* A channel is associated with a single facility, with the level being
* specified when a message is written. Normally, a <CODE>LogChannel</CODE>
* is obtained once at initialization time and use repeatedly. It is
* permissible to obtain multiple references to the log channel for a facility,
* but this is discouraged for performance reasons.<P>
*
* Log messages, even debugging ones, should be defined with care. They
* should be terse, but clear to someone who isn't intimately familiar with
* the code. Permanent debugging messages should be designed with the idea
* of use when supportting a deployed product.<P>
*
* The central logging object needs to be configured very early in the startup
* process. If logging can't be configured, then the startup should be aborted
* or a object created that does some simple form of logging, such as write
* to <CODE>stderr<CODE>. A client should never have to check if the global
* logger object exists.<P>
*
*/
public abstract class Logger {
/**
* Standard level.
*/
public static final int LOGMODE_NORMAL = 1;
/**
* A condition that should be corrected immediately
*/
public static final int LOGMODE_NONE = 0;
/**
* Critical conditions.
*/
public static final int LOGMODE_FULL = 2;
public static final String strLOGMODE_NONE = "NONE";
public static final String strLOGMODE_NORMAL = "NORMAL";
public static final String strLOGMODE_FULL = "FULL";
public boolean[] enbledLogLevels;
/**
* Global <CODE>Logger</CODE> object.
*/
protected static Logger centralLogger;
/**
* Table of standard level names
*/
protected static final String[] standardLevelNames = {
strLOGMODE_NORMAL, // 0
strLOGMODE_NONE, // 1
strLOGMODE_FULL // 2
};
/**
* Get the central (global) logging object.
*
* @return A reference the object. If the facility has not been
* initialized <CODE>null</CODE> is returned. However, this is
* considered a bug in the design of the initialization. Clients
* do not need to check for <CODE>null</CODE>.
*/
public static Logger getCentralLogger() {
return centralLogger;
}
/**
* Configure Logger with given config file, interpreting of config file is
* logger implementation specific.
*
* @param confFilePath Path to configuration file.
* @throws Exception
*/
abstract public void configure(String confFilePath) throws Exception;
/**
* Determine if logging is enabled for the specified level. This
* is useful to prevent a series of unnecessary logging calls,
* as often encountered with debug logging, or a call where generating
* the message is expensive.
*
* @param level Numeric level that is to be checked.
* @return <CODE>true</CODE> if enabled, <CODE>false</CODE> if not
* enabled.
*/
abstract public boolean isEnabled(int level);
/**
* Determine if logging is enabled for the specified level. This
* is useful to prevent a series of unnecessary logging calls,
* as often encountered with debug logging, or a call where generating
* the message is expensive.
*
* @param level Symbolic level that is to be checked.
* @return <CODE>true</CODE> if enabled, <CODE>false</CODE> if not
* enabled.
*/
abstract public boolean isEnabled(String level);
/**
* Convert a symbolic level to an integer identifier.
*
* @param level Symbolic level to convert
* @return The numeric level identifier
*/
abstract public int getLevel(String level);
/**
* Write a string to the log file.
*
* @param level Numeric level the message is associated with.
* @param msg The message to log.
*/
abstract public void write(int level, String msg);
/**
* Write a string to the log file.
*
* @param level Symbolic level the message is associated with.
* @param msg The message to log.
*/
abstract public void write(String level, String msg);
/**
* Write a string and exception to the log file.
*
* @param level Numeric level the message is associated with.
* @param msg The message to log.
* @param throwable Exception or error to log.
*/
abstract public void write(int level, String msg, Throwable throwable);
/**
* Write a string and exception to the log file.
*
* @param level Symbolic level the message is associated with.
* @param msg The message to log.
* @param throwable Exception or error to log.
*/
abstract public void write(String level, String msg, Throwable throwable);
abstract public boolean[] getEnabledLogLevels();
abstract public void setEnabledLogLevels(String logMode);
abstract public boolean setMessage(String key, String value);
abstract public String getMessage(String key);
abstract public boolean writeEcho (String strLogTxt);
abstract public void close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -