关闭

LoggerUtils

标签: objectclassstringnull
263人阅读 评论(0) 收藏 举报

private static Hashtable<String, LoggerUtils> instances = new Hashtable<String, LoggerUtils>();

private Class< ? > logClass;

private LoggerUtils(){}

public void setLogClass(Class< ? > logClass){
        this.logClass = logClass;
 }

public Class< ? > getLogClass(){
        return logClass;
}

public static LoggerUtils getInstance(Class< ? > logClass)
    {
        LoggerUtils fileLogger = (LoggerUtils) instances.get(logClass.getName());

        if (null == fileLogger)
        {
            fileLogger = new LoggerUtils();
            fileLogger.setLogClass(logClass);
            instances.put(logClass.getName(), fileLogger);
        }
        return fileLogger;
    }

 public void saveLogToFile(LogLevel level, String obj)
    {
        switch (level)
        {
            case DEBUG :
                this.debug(obj);
                break;
            case ERROR :
                this.error(obj);
                break;
            case INFO :
                this.info(obj);
                break;
            case WARN :
                this.warn(obj);
                break;
            default:
                break;
        }
    }

 private void info(Object obj){
        LogFactory.getLog(logClass).info(obj);
 }

 private void debug(Object obj) {
        LogFactory.getLog(logClass).debug(obj);
 }

private void warn(Object obj){
        LogFactory.getLog(logClass).warn(obj);
}

private void error(Object obj){
        LogFactory.getLog(logClass).error(obj)

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:91463次
    • 积分:1474
    • 等级:
    • 排名:千里之外
    • 原创:67篇
    • 转载:12篇
    • 译文:0篇
    • 评论:5条
    最新评论