forumlog.java
来自「jGossip是一个简单而功能强大的Java论坛软件(消息板)」· Java 代码 · 共 116 行
JAVA
116 行
/*
* $$Id: ForumLog.java,v 1.4 2004/01/26 11:32:05 bel70 Exp $$
*
* ***** BEGIN LICENSE BLOCK *****
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and
* limitations under the License.
*
* The Original Code is JGossip forum code.
*
* The Initial Developer of the Original Code is the JResearch, Org.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dmitry Belov <bel@jresearch.org>
*
* ***** END LICENSE BLOCK ***** */
/*
* Created on Oct 14, 2003
*
*/
package org.jresearch.gossip.log;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Jdk14Logger;
import org.apache.commons.logging.impl.Log4JLogger;
import org.jresearch.gossip.IConst;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Properties;
import java.util.logging.FileHandler;
import java.util.logging.SimpleFormatter;
/**
* DOCUMENT ME!
*
* @author Bel
*/
public class ForumLog {
private static ForumLog ourInstance;
private Log forumLogger;
private ForumLog() {
forumLogger = LogFactory.getLog(IConst.LOG.FORUM);
Properties prop = new Properties();
if (forumLogger instanceof Log4JLogger) {
try {
prop.load(getClass().getClassLoader().getResourceAsStream("org/jresearch/gossip/resources/log4j.properties"));
Method configure = Class.forName(
"org.apache.log4j.PropertyConfigurator")
.getDeclaredMethod("configure",
new Class[] { Properties.class });
Object Configurator = Class.forName(
"org.apache.log4j.PropertyConfigurator").newInstance();
configure.invoke(Configurator, new Object[] { prop });
} catch (Exception e) {
e.printStackTrace();
}
} else if (forumLogger instanceof Jdk14Logger) {
try {
prop.load(getClass().getClassLoader().getResourceAsStream("org/jresearch/gossip/resources/jdk14log.properties"));
Object handler = null;
if (prop.getProperty("logs.type").equalsIgnoreCase("f")) {
handler = new FileHandler(prop.getProperty("file"),
Integer.parseInt(prop.getProperty("limit")),
Integer.parseInt(prop.getProperty("count")), true);
((FileHandler) handler).setFormatter(new SimpleFormatter());
((Jdk14Logger) forumLogger).getLogger().addHandler((FileHandler) handler);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* Method <code>getInstance</code> return instance
*
* @return instance
*/
public synchronized static ForumLog getInstance() {
if (ourInstance == null) {
ourInstance = new ForumLog();
}
return ourInstance;
}
/**
* Method <code>getForumLogger</code> return forum logger
*
* @return forum logger
*/
public Log getForumLogger() {
return forumLogger;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?