亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? dbloglistener.java

?? pl/sql中記log的函數
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
package log4plsql.backgroundProcess;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;


import oracle.jdbc.pool.OracleDataSource;
import oracle.xml.parser.v2.XMLNode;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
import org.apache.log4j.spi.LoggingEvent;

/**
 * <p>Title:        DbLogListener</p>
 * <p>Description:  Loops on a given connection, reading messages from the Log4Plsql pipe on the other end.
 * Default logging is by Log4Plsql section as the Logger name.  Change the DbLogHelper class to do special Logger configuration.
 * <p>
 * <p>Copyright:    Copyright (c) 2004 Sabrix, Inc.  This material is confidential and may not be reproduced by any means.</p>
 * <p>Company:      Sabrix, Inc.</p>
 * <p>Header:       $Header: $</p>
 * @author gregw
 * @version $Version:$
 */
public class DbLogListener implements Runnable {
	
	/**
	 * Default to 5 minute wait for the next pipe message before returning and starting the loop again.
	 * It can take up to this long for the class to see a change to the keepWatching flag and stop processing logs.
	 */
	public static final int DEFAULT_PIPE_TIMEOUT = 300;
	
	/**
	 * Constant for Log4Plsql level value.  maps to relevant Log4J Level constant.
	 */
	public static final Integer LEVEL_OFF = new Integer(10);
	/**
	 * Constant for Log4Plsql level value.  maps to relevant Log4J Level constant.
	 */
	public static final Integer LEVEL_FATAL = new Integer(20);
	/**
	 * Constant for Log4Plsql level value.  maps to relevant Log4J Level constant.
	 */
	public static final Integer LEVEL_ERROR = new Integer(30);
	/**
	 * Constant for Log4Plsql level value.  maps to relevant Log4J Level constant.
	 */
	public static final Integer LEVEL_WARN = new Integer(40);
	/**
	 * Constant for Log4Plsql level value.  maps to relevant Log4J Level constant.
	 */
	public static final Integer LEVEL_INFO = new Integer(50);
	/**
	 * Constant for Log4Plsql level value.  maps to relevant Log4J Level constant.
	 */
	public static final Integer LEVEL_DEBUG = new Integer(60);
	/**
	 * Constant for Log4Plsql level value.  maps to relevant Log4J Level constant.
	 */
	public static final Integer LEVEL_ALL = new Integer(70);
	
	/**
	 * Mapped Domain Context value for Appender formatting
	 */
	public static final String MDC_ID = "LOG4PLSQL_ID";
	/**
	 * Mapped Domain Context value for Appender formatting
	 */
	public static final String MDC_DATE = "LOG4PLSQL_DATE";
	/**
	 * Mapped Domain Context value for Appender formatting
	 */
	public static final String MDC_USER = "LOG4PLSQL_USER";
	
	/**
	 * Map linking Log4Plsql level values to Log4J level constant instances.  Yes, this adds maintenance overhead,
	 * but really, how often will new log levels be defined?  And querying for them dynamically needs a connection,
	 * which means it would have to be done per instance, which seems needlessly expensive.  This can be changed if
	 * custom log levels are truely that desirable.
	 */
	private static final Map logLevels_ = new HashMap();
	
	static {
		logLevels_.put(LEVEL_OFF, Level.OFF);
		logLevels_.put(LEVEL_FATAL, Level.FATAL);
		logLevels_.put(LEVEL_ERROR, Level.ERROR);
		logLevels_.put(LEVEL_WARN, Level.WARN);
		logLevels_.put(LEVEL_INFO, Level.INFO);
		logLevels_.put(LEVEL_DEBUG, Level.DEBUG);
		logLevels_.put(LEVEL_ALL, Level.ALL);
	}
	
	/**
	 * Generate the proper statement to get log pipe messages.  This statement can be executed repeatedly.
	 * 
	 * @param conn the database connection to use
	 * @param timeout seconds to wait for a new message if no message is currently in the pipe.
	 * @return
	 * @throws SQLException
	 */
	private static CallableStatement getDbLogPipeReadStatement(Connection conn, int timeout, String pipeName) throws SQLException {
		CallableStatement stmt = conn.prepareCall("BEGIN :1 := PLOG_PIPE.read_message(:2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14); END;");
		
		stmt.registerOutParameter(1, Types.INTEGER);		// 1. return value
		stmt.setInt(2, timeout);								// 2. seconds to wait for the next message
		stmt.registerOutParameter(3, Types.BIGINT);		// 3. ID
		stmt.registerOutParameter(4, Types.TIMESTAMP);	// 4. Date
		stmt.registerOutParameter(5, Types.INTEGER);		// 5. hundredths of seconds for date
		stmt.registerOutParameter(6, Types.INTEGER);		// 6. level
		stmt.registerOutParameter(7, Types.VARCHAR);		// 7. section
		stmt.registerOutParameter(8, Types.VARCHAR);		// 8. user
		stmt.registerOutParameter(9, Types.VARCHAR);		// 9. log command
		stmt.registerOutParameter(10, Types.VARCHAR);	//10. message text
		stmt.registerOutParameter(11, Types.VARCHAR);	//11. MDC keys
		stmt.registerOutParameter(12, Types.VARCHAR);	//12. MDC values
		stmt.registerOutParameter(13, Types.VARCHAR);	//13. MDC separator
		stmt.setString(14, pipeName);							//14. Pipe name to read from.
		
		return stmt;
	}

	private static Map dbLogListeners_ = new HashMap();
	
	/**
	 * Gets the instance of DbLogListener for the given connection.  If it does not exist, it is created with the default base logger and timeout.
	 * @param conn
	 * @return
	 * @throws SQLException
	 */
	public static DbLogListener getDbLogListener(Connection conn) throws SQLException {
		return getDbLogListener(conn, null, DEFAULT_PIPE_TIMEOUT, null);
	}
	/**
	 * Gets the instance of DbLogListener for the given connection.  If it does not exist, it is created with the default base logger and timeout.
	 * @param conn
	 * @param pipeName
	 * @return
	 * @throws SQLException
	 */
	public static DbLogListener getDbLogListener(Connection conn, String pipeName) throws SQLException {
		return getDbLogListener(conn, null, DEFAULT_PIPE_TIMEOUT, pipeName);
	}
	/**
	 * Gets the instance of DbLogListener for the given connection.  If it does not exist, it is created with the given base logger and the default timeout.
	 * @param conn
	 * @return
	 * @throws SQLException
	 */
	public static DbLogListener getDbLogListener(Connection conn, Logger rootLogger) throws SQLException {
		return getDbLogListener(conn, rootLogger, DEFAULT_PIPE_TIMEOUT, null);
	}
	/**
	 * Gets the instance of DbLogListener for the given connection.  If it does not exist, it is created with the given base logger and the default timeout.
	 * @param conn
	 * @param pipeName
	 ` * @return
	 * @throws SQLException
	 */
	public static DbLogListener getDbLogListener(Connection conn, Logger rootLogger, String pipeName) throws SQLException {
		return getDbLogListener(conn, rootLogger, DEFAULT_PIPE_TIMEOUT, pipeName);
	}
	/**
	 * Create or retrieve the database log pipe listener for the given connection.  Assumes the schema on the other
	 * end of the connection contains Log4Plsql package PLOG_PIPE to read from a given pipe.
	 * <p>
	 * Only one instance can exist at a time per connection/username/pipe combination, so all messages are sure to go to the same Logger.
	 * If public pipes are being used, there is still a possibility of duplicate DbLogListener instances listening to the same pipe from 
	 * different user connections.
	 * <p>
	 * Messages will be logged using Logger instances decended from the given named Logger,
	 * which is assumed to already be configured.  If rootLoggerName is null, the default is assumed
	 * to be the Root Logger.
	 * <p>
	 */
	public static DbLogListener getDbLogListener(Connection conn, Logger rootLogger, int pipeTimeout, String pipeName) throws SQLException {
		DatabaseMetaData metaData = conn.getMetaData();
		String key = metaData.getURL() + "-" + metaData.getUserName() + "-" + pipeName;
		DbLogListener listener = null;
		synchronized (dbLogListeners_) {
			listener = (DbLogListener) dbLogListeners_.get(key);
			if (listener == null) {
				listener = new DbLogListener(conn, key, rootLogger, pipeTimeout, pipeName);
				dbLogListeners_.put(key, listener);
			}
		}
		return listener;
	}
	public static DbLogListener getDbLogListener(Connection conn, Logger rootLogger, int pipeTimeout) throws SQLException {
		return getDbLogListener(conn, rootLogger, pipeTimeout, null);
	}
	
	/**
	 * Removes a DBLogListener from the map based on it's connection URL/username key string.
	 * Stops the listener from listening, if it hasn't already stopped, and removes it from the map.
	 * Call this to clean up the map.  Otherwise, the same listeners will be reused, just stopped and started
	 * multiple times, if desired.
	 * @param key
	 */
	public static void removeDbLogListener(String key) {
		synchronized (dbLogListeners_) {
			DbLogListener listener = (DbLogListener) dbLogListeners_.get(key);
			listener.setStillWatching(false);
			dbLogListeners_.remove(key);
		}
	}
	
	/**
	 * Connection to use for reading the Oracle pipe.
	 */
	private Connection conn_;
	/**
	 * Base Logger name string to append the current context to.  If null, then the root logger is assumed to be the parent
	 * Logger for all Log4Plsql messages.
	 */
	private String rootLoggerName_ = null;
	
	/**
	 * Flag to stop looping for messages.
	 */
	private boolean stillWatching_ = true;
	/**
	 * Object to lock on to make changing the value of stillWatching_ thread safe.
	 */
	private Object stillWatchingLock_ = new Object();
	
	private String mapKey_;
	
	private boolean isRunning_ = false;
	private Object isRunningLock_ = new Object();
	
	private CallableStatement stmt_;
	
	/**
	 * Name of Oracle Pipe to read from.  If null, use the Log4Plsql default pipe name found in the PLOGPARAM package.
	 */
	private String pipeName_;
	
	/**
	 * Sequential identifier of the current log message - 0 = no current message.
	 */
	private long id_;
	
	/**
	 * Date stamp of the current log message.  Granularity to hundredths of seconds only.
	 */
	private Date date_;
	
	/**
	 * Log message level - current value is looked up in the DB log level map.
	 */
	private Level level_;
	
	/**
	 * Log4Plsql section for the current message, composed of period delimited strings.  
	 * This commonly maps to a Logger name.  The default implementation appends this to any
	 * root logger name given in the factory constructor to define the Logger name to use.
	 */
	private String section_;
	
	/**
	 * Database user the current log message comes from.  May or may not be useful depending on the app architecture.
	 */
	private String user_;
	
	/**
	 * Text of the current log message.
	 */
	private String message_;
	
	/**
	 * Current Log command from the pipe.  Currently does nothing, as there is only one command.
	 */
	private String command_;
	
	/**
	 * MDC keys for the current message.
	 */
	private List mdcKeys_ = new ArrayList();
	
	/**
	 * MDC values for the current message.
	 */
	private List mdcValues_ = new ArrayList();
	
	/**
	 * MDC Seprarator for the current message.
	 */
	private String mdcSeparator_;
	
	/**
	 * Class that provides logic to decide what Logger instance to use for a given message statement, assuming multiple
	 * logical loggers use the same database pipe.  The default implementation uses the message section appended to the
	 * base logger name given in the factory (constructor) call as the logger name.
	 */
	private DbLogHelper dbLogHelper_ = new DbLogHelper(this);
	
	/**
	 * Create a new listener ready to read messages from the given connection.  Called by factory methods and unit tests.
	 * <p/>
	 * 
	 * @param conn Connection to read pipe from
	 * @param key map key for this object.  From factory method, and used by remove method.
	 * @param rootLogger base Logger pipe message loggers.  Can be null.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
青青草国产精品97视觉盛宴| caoporn国产精品| 欧美va亚洲va在线观看蝴蝶网| 老鸭窝一区二区久久精品| 日韩免费一区二区| 国产一区二区剧情av在线| 国产亚洲福利社区一区| 亚洲视频香蕉人妖| 91在线观看免费视频| 一区二区三区在线观看国产| 欧美三区在线视频| 免费在线观看不卡| 久久综合狠狠综合久久综合88| 高清成人在线观看| 中文字幕一区二区不卡 | 麻豆一区二区三| 日韩欧美区一区二| 国产成人在线网站| 亚洲欧美另类综合偷拍| 欧美日本在线观看| 精品一区二区三区的国产在线播放 | 久久亚区不卡日本| 成人白浆超碰人人人人| 亚洲精品日韩一| 日韩一级二级三级精品视频| 国产精品一卡二| 亚洲日本成人在线观看| 欧美高清hd18日本| 国v精品久久久网| 亚洲一二三四在线观看| 精品sm捆绑视频| 99国产精品国产精品毛片| 五月婷婷另类国产| 久久久精品综合| 欧美综合在线视频| 麻豆成人综合网| 亚洲欧美在线视频| 777午夜精品视频在线播放| 国产福利一区在线观看| 亚洲综合小说图片| 久久久久成人黄色影片| 91久久国产综合久久| 精品亚洲成a人在线观看 | 亚洲国产精品麻豆| 久久久久久免费网| 欧美日韩在线三级| 粉嫩高潮美女一区二区三区 | 久久成人羞羞网站| 综合激情成人伊人| 日韩欧美视频一区| 91九色最新地址| 国产夫妻精品视频| 五月天丁香久久| 中文一区在线播放| 在线播放中文一区| av动漫一区二区| 久久成人av少妇免费| 亚洲免费观看高清完整版在线观看熊| 国产乱国产乱300精品| 亚洲成av人片在线| 国产精品久久久久一区二区三区共| 3d动漫精品啪啪一区二区竹菊| 99精品国产视频| 国产乱色国产精品免费视频| 日韩精品电影一区亚洲| 日韩理论电影院| 久久久综合视频| 欧美日韩aaaaaa| 色综合天天天天做夜夜夜夜做| 国产激情视频一区二区在线观看| 日韩国产高清影视| 亚洲另类在线一区| 国产日韩欧美精品在线| 欧美一区二区三区在线视频| 在线视频观看一区| 成人av集中营| 国产在线视频不卡二| 日韩精品一区第一页| 一区二区三区精品视频| 中文字幕av在线一区二区三区| 26uuu欧美| 欧美r级在线观看| 在线综合+亚洲+欧美中文字幕| 色婷婷香蕉在线一区二区| 国产91在线观看丝袜| 国产一区亚洲一区| 久久电影网电视剧免费观看| 日韩va亚洲va欧美va久久| 亚洲国产精品一区二区久久恐怖片| 亚洲欧美色一区| 中文字幕欧美一区| 99久久国产综合精品女不卡| 国产福利精品导航| 国内精品伊人久久久久av一坑| 免费在线观看一区| 首页国产欧美日韩丝袜| 亚洲午夜激情av| 一区二区欧美国产| 一区二区三区四区中文字幕| 亚洲欧美日韩中文播放| 中文字幕在线免费不卡| 国产欧美日韩在线看| 久久久噜噜噜久久中文字幕色伊伊| 精品国产麻豆免费人成网站| 日韩精品一区在线| 精品少妇一区二区三区视频免付费 | 在线不卡免费欧美| 在线不卡欧美精品一区二区三区| 欧美日产国产精品| 在线播放国产精品二区一二区四区| 欧美日韩激情在线| 欧美亚洲另类激情小说| 欧美三级中文字| 欧美日韩精品免费| 91精品国产综合久久福利| 欧美一卡二卡在线观看| 日韩午夜精品电影| 精品福利一二区| 久久精品欧美一区二区三区不卡| 国产日韩欧美麻豆| 日韩一区在线看| 亚洲午夜私人影院| 日本不卡免费在线视频| 激情小说欧美图片| 国产成人精品一区二区三区网站观看| 国产999精品久久| 色菇凉天天综合网| 91麻豆精品国产| 精品裸体舞一区二区三区| 不卡一区在线观看| 一道本成人在线| 欧美三级电影精品| 日韩美一区二区三区| 久久精品人人爽人人爽| 国产精品动漫网站| 亚洲一区免费在线观看| 天堂av在线一区| 久久成人免费电影| 国产精品一区在线| 成人一区二区三区视频在线观看| 男人的天堂久久精品| 日本欧美一区二区三区| 日韩不卡一区二区三区| 视频一区中文字幕国产| 久久精品国产网站| 国产一二精品视频| 精品一区中文字幕| 婷婷六月综合网| 欧美v亚洲v综合ⅴ国产v| 91久久一区二区| 青青草国产成人av片免费| 欧美激情一区三区| 欧美一区二区三区四区视频| 日本女人一区二区三区| 久久久久久黄色| 精品视频全国免费看| 床上的激情91.| 久久精品国产在热久久| 亚洲第一福利视频在线| 久久亚洲捆绑美女| 欧美理论电影在线| 777久久久精品| 国产肉丝袜一区二区| 中文字幕中文在线不卡住| 一区二区在线观看免费| 日产国产高清一区二区三区 | 欧美亚洲日本国产| 欧美一区永久视频免费观看| 国产欧美综合色| 亚洲午夜久久久久久久久久久 | 国产成人av自拍| 色婷婷av一区二区| 欧美一区二区观看视频| 中文字幕一区二区不卡| 亚洲二区视频在线| 国产一区不卡视频| 色综合视频一区二区三区高清| 欧美电影免费观看高清完整版在| 中文字幕在线观看不卡视频| 午夜精品久久久| 顶级嫩模精品视频在线看| 欧美日韩国产综合视频在线观看| 久久天堂av综合合色蜜桃网| 亚洲另类在线视频| 乱中年女人伦av一区二区| 色狠狠色狠狠综合| 精品免费99久久| 亚洲激情欧美激情| 精品一区二区久久| 欧美色图天堂网| 久久精品免费在线观看| 亚洲一区二区在线免费观看视频| 国产毛片精品视频| 91麻豆精品国产91| 中文字幕一区二区三区色视频| 五月综合激情日本mⅴ| 成人成人成人在线视频| 久久综合色综合88| 亚洲国产精品久久人人爱| 成人在线综合网|