改进log类的write方法 增加log_write标签位 可用于绑定行为

增加send方法 用于发送预警(需要先alarm方法初始化)
This commit is contained in:
thinkphp
2015-12-29 10:12:20 +08:00
parent b767dcef11
commit fd99559c59

View File

@@ -80,24 +80,34 @@ class Log
} }
/** /**
* 实时写入日志信息 并支持异常和错误预警通知 * 实时写入日志信息 并支持行为
* @param mixed $msg 调试信息 * @param mixed $msg 调试信息
* @param string $type 信息类型 * @param string $type 信息类型
* @return void * @return void
*/ */
public static function write($msg, $type) public static function write($msg, $type = 'log')
{ {
if (!is_string($msg)) { if (!is_string($msg)) {
$msg = print_r($msg, true); $msg = print_r($msg, true);
} }
if ('error' == $type) { // 封装日志信息
// 预留预警通知接口
self::$alarm && self::$alarm->send($msg);
}
$log[] = ['type' => $type, 'msg' => $msg]; $log[] = ['type' => $type, 'msg' => $msg];
// 监听log_write
APP_HOOK && Hook::listen('log_write', $log);
// 写入日志
self::$driver && self::$driver->save($log); self::$driver && self::$driver->save($log);
} }
/**
* 发送预警通知
* @return void
*/
public static function send($msg)
{
self::$alarm && self::$alarm->send($msg);
}
// 静态调用 // 静态调用
public static function __callStatic($method, $args) public static function __callStatic($method, $args)
{ {