一个基于 Easylogging++ 的 php 扩展高性能日志库
//clone 目录
git clone https://github.com/cdoco/easylog
//编译安装
cd easylog && phpize && ./configure && make && make install
extension=easylog.so
[easylog]
//需要配置文件 配置文件的格式见下文
easylog.config_file = "/data/easylog.conf"
//配置日志级别 目前支持级别: global trace debug fatal error warning verbose info unknown
easylog.log_level = "info"
<?php
//设置日志级别
Easylog::setLevel(Easylog::ERROR);
//自定义格式符
Easylog::setCustomFormat("%ip", "172.16.2.111");
//设置 logger ID
//这个 id 必须在配置文件中存在
$easylog = new Easylog("easylog");
//设置 info 级别的格式
$easylog->setFormat(Easylog::INFO, "[%datetime{%Y-%M-%d %H:%m:%s}] %logger.%level %ip | %msg");
$easylog->info("info");
$easylog->warning("warning");
$easylog->error("error");
$easylog->debug("debug");
$easylog->trace("trace");
$easylog->fatal("fatal");
$zy = new Easylog("zy");
//设置格式化符
$zy->setFormat(Easylog::GLOBAL, "[%datetime{%Y-%M-%d %H:%m:%s}] %logger.%level | %msg");
//设置是否需要写到文件
$zy->setToFile(Easylog::GLOBAL, "true");
//设置写到文件的文件名
$zy->setFileName(Easylog::GLOBAL, "/data/logs/php/zy.log");
$zy->info("info");
$zy->warning("warning");
-- default // logger id
* GLOBAL:
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
FORMAT = "[%datetime{%Y-%M-%d %H:%m:%s}] %logger.%level | %msg"
FILENAME = "/data/logs/php/log_%datetime{%Y%M%d}.log"
MILLISECONDS_WIDTH = 3
PERFORMANCE_TRACKING = false
MAX_LOG_FILE_SIZE = 1048576
LOG_FLUSH_THRESHOLD = 0
* TRACE:
FILENAME = "/data/logs/php/trace_%datetime{%Y%M%d}.log"
* DEBUG:
FILENAME = "/data/logs/php/debug_%datetime{%Y%M%d}.log"
* FATAL:
ENABLED = false
* ERROR:
FILENAME = "/data/logs/php/error_%datetime{%Y%M%d}.log"
* WARNING:
FILENAME = "/data/logs/php/warning_%datetime{%Y%M%d}.log"
* INFO:
FILENAME = "/data/logs/php/info_%datetime{%Y%M%d}.log"
* VERBOSE:
ENABLED = false
-- easylog // logger id
* GLOBAL:
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
FORMAT = "[%datetime{%Y-%M-%d %H:%m:%s}] %logger.%level | %msg"
FILENAME = "/data/logs/php/easylog/log_%datetime{%Y%M%d}.log"
MILLISECONDS_WIDTH = 3
PERFORMANCE_TRACKING = false
MAX_LOG_FILE_SIZE = 1048576
LOG_FLUSH_THRESHOLD = 0
* INFO:
FILENAME = "/data/logs/php/easylog/info_%datetime{%Y%M%d}.log"
* ERROR:
FILENAME = "/data/logs/php/easylog/error_%datetime{%Y%M%d}.log"
1
crabRunning 2017-07-07 17:13:36 +08:00
有个类似的 seaslog
|
2
Roope 2017-07-07 17:52:37 +08:00
高总 6666
|
3
iamfirst 2017-07-09 12:32:53 +08:00 via Android
帮顶,最近也在深入了解 php 内核,准备用 c 来写扩展
|