📄 log4jlistener.java
字号:
/* * jPOS Project [http://jpos.org] * Copyright (C) 2000-2008 Alejandro P. Revilla * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */package org.jpos.util;import java.io.ByteArrayOutputStream;import java.io.PrintStream;import org.apache.log4j.Level;import org.apache.log4j.xml.DOMConfigurator;import org.apache.log4j.helpers.FileWatchdog;import org.jpos.core.Configuration;import org.jpos.core.ConfigurationException;import org.jpos.core.ReConfigurable;/** * @author Eoin P. FLood</a> * @version $Revision: 2594 $ $Date: 2008-01-22 14:41:31 -0200 (Tue, 22 Jan 2008) $ * @see org.jpos.util.LogListener * @see org.jpos.util.LogEvent * @since jPOS 1.3 * * This class acts as a simple bridge between jPOS's logging system * and log4j. * The jPOS <code>realm</code> is used as the log4j <code>Logger</code> * and messages are by default logged with the DEBUG level. This can * be changed by calling <code>setLevel</code> */public class Log4JListener implements LogListener, ReConfigurable{ private Level _level; /** * Create a new Log4JListener with DEBUG level. */ public Log4JListener () { setLevel (Level.DEBUG_INT); } public void setLevel (int level) { _level = Level.toLevel (level); } public void setLevel (String level) { _level = Level.toLevel (level); } public void close() { } /** * Expects the following properties: * <ul> * <li>config - Configuration file path * <li>priority - Log4J priority (debug, info, warn, error) * <li>watch - interval (in ms) to monitor XML config file for changes * </ul> */ public void setConfiguration (Configuration cfg) throws ConfigurationException { String config = cfg.get ("config"); long watch = cfg.getLong ("watch"); if (watch == 0) watch = FileWatchdog.DEFAULT_DELAY; if ( (config!=null) && (!config.trim().equals("")) ) DOMConfigurator.configureAndWatch (config, watch); setLevel (cfg.get ("priority")); } public synchronized LogEvent log (LogEvent ev) { org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger ( ev.getRealm().replace('/', ':') ); if (logger.isEnabledFor ( _level)) { ByteArrayOutputStream w = new ByteArrayOutputStream (); PrintStream p = new PrintStream (w); ev.dump (p, ""); logger.log (_level, w.toString()); } return ev; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -