📄 syslog.java
字号:
/*
/*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Created on 2006/8/25
*
* @Author: Xiaojun Chen
* $Revision$ 1.0
*
*/
package eti.bi.common.System;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import eti.bi.exception.SysException;
public class SysLog {
static Logger logger = Logger.getLogger(SysLog.class.getName());
//path relative to root
private static String logHOME;
private static String logfile = "Log.properties";
private static boolean init = false;
/**
* initial
* @throws SysException
* @throws Exception
* */
public static void initialize() throws SysException, Exception{
if(!init){
//initial
logHOME = SysConfig.getSystemHome()+File.separator+"log";
loadConfig(logHOME+File.separator+logfile);
setLevel(Level.INFO);
}
}
/**
* return the configuration of log
* */
public static String getConfigurate(){
return "";
}
/**
* default configuration and level
* */
public static void log(String inform) {
logger.info(inform);
}
/**
* @throws Exception
*
* */
public static void log(String config, Level level,String inform) throws Exception{
if(config!=null){
loadConfig(config);
}
if(level!=null){
setLevel(level);
}
log(inform);
}
private static void loadConfig(String logproperty) throws Exception{
if(logproperty==null){
throw new Exception("no such log file:"+logproperty,null);
}
Properties props = new Properties();
FileInputStream istream = new FileInputStream(logproperty);
props.load(istream);
if(props.getProperty("log4j.appender.ICE")==null){
throw new Exception("No ICE appender",null);
}
String logFile = logHOME + File.separator+props.getProperty("log4j.appender.ICE.File");
File file = new File(logFile);
if(!file.exists()) {
if(!file.createNewFile()) {
throw new Exception("Can't create log file "+logFile,null);
}
}
props.setProperty("log4j.appender.ICE.File", logFile);
PropertyConfigurator.configure(props);
}
private static void setLevel(Level level) throws Exception{
try{
logger.setLevel(level);
}
catch(Exception e){
throw new Exception(e);
}
}
public static void debug(Object arg0) {
logger.debug(arg0);
}
public static void debug(Object arg0, Throwable arg1) {
logger.debug(arg0, arg1);
}
public static void info(Object arg0) {
logger.info(arg0);
}
public static void info(Object arg0, Throwable arg1) {
logger.info(arg0, arg1);
}
public static void warn(Object arg0) {
logger.warn(arg0);
}
public static void warn(Object arg0, Throwable arg1) {
logger.warn(arg0, arg1);
}
public static void error(Object arg0) {
logger.error(arg0);
}
public static void error(Object arg0, Throwable arg1) {
logger.error(arg0, arg1);
}
public static void fatal(Object arg0) {
logger.fatal(arg0);
}
public static void fatal(Object arg0, Throwable arg1) {
logger.fatal(arg0, arg1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -