YULRedisLogger.class.php 1.32 KB
<?php
require_once dirname(__FILE__).'/config/redisLogger.const.inc.php';
require_once dirname(__FILE__).'/loggerMQ/YMQLoggerRecorder.class.php';

class YULRedisLogger {

	private static $LOG_SEPARATOR = '|';
	
	public static function log($userID, $funcID, $param, $result, $ip, $client)
	{
		$data = self::_buildLogData($userID, $funcID, $param, $result, $ip, $client);
		
		self::_log($data, REDIS_LOGGER_TYPE_OPT);
	}
	
	private static function _log($data, $type = REDIS_LOGGER_TYPE_OPT)
	{
		YMQLoggerRecorder::set($type, $data);
	}
	
	public static function persist()
	{
		YMQLoggerRecorder::save();
	}
	/**
	 * 用户ID|方法ID|调用的参数|返回值|时间|IP地址|浏览器类型
	 * 
	 * Enter description here ...
	 * @param unknown_type $userID
	 * @param unknown_type $funcID
	 * @param unknown_type $param
	 * @param unknown_type $result
	 * @param unknown_type $ip
	 * @param unknown_type $client
	 */
	private static function _buildLogData($userID, $funcID, $param, $response, $ip, $client)
	{
		$result = $userID;
		$result .= self::$LOG_SEPARATOR.$funcID;
		
		$result .= self::$LOG_SEPARATOR.json_encode($param);
		$result .= self::$LOG_SEPARATOR.json_encode($response);
		$result .= self::$LOG_SEPARATOR.time();
		$result .= self::$LOG_SEPARATOR.$ip;
		$result .= self::$LOG_SEPARATOR.$client;
		
		return $result;
	}
}

?>