高性能PHP日志库SeasLog使用

官方介绍

安装方式

# 先安装 PECL
cd /usr/local/php/bin/  
curl -o go-pear.php http://pear.php.net/go-pear.phar  
./php go-pear.php

# 回车, 会提示选择安装的东西, 直接回车, 安装全部, 若后面有要选择y/n的, 输入y回车

# 安装SeasLog
pecl install seaslog

# 重启nginx
/etc/init.d/nginx restart

安装并重启完成后就能在phpinfo()看到seasLog信息了

使用

# 配置基础路径, 输出路径为 ~/logs/default/20180315.log
SeasLog::setBasePath(__DIR__.'/logs');

#设置模块名称,替换上面的default
SeasLog::setLogger('testModule');

# 使用
SeasLog::log(SEASLOG_ERROR,'this is a error test by ::log');

SeasLog::debug('this is a {userName} debug',array('{userName}' => 'neeke'));

SeasLog::info('this is a info log');

SeasLog::notice('this is a notice log');

SeasLog::warning('your {website} was down,please {action} it ASAP!',array('{website}' => 'github.com','{action}' => 'rboot'));

SeasLog::error('a error log');

SeasLog::critical('some thing was critical');

SeasLog::alert('yes this is a {messageName}',array('{messageName}' => 'alertMSG'));

SeasLog::emergency('Just now, the house next door was completely burnt out! {note}',array('{note}' => 'it`s a joke'));

日志格式介绍

# 默认格式
2018-03-15 19:03:16 | ERROR | 10048 | 5aaa52f4c3f6e | 1521111796.802 | this is a error test by ::log

# 字段意义
{dateTime} | {level} | {pid} | {uniqid} | {timeStamp} | {logInfo}

参考文档