tm / error-log-parser
该包已被废弃,不再维护。未建议替代包。
PHP error_log 解析库。
1.2.1
2017-10-30 07:42 UTC
Requires
- php: >=5.6.0
Requires (Dev)
- phpunit/phpunit: 5.7.*
README
这是一个简单的PHP库,用于解析Apache或Nginx错误日志文件条目以供进一步使用。
安装
使用Composer
$ composer require tm/error-log-parser
或者手动将其添加到composer.json文件中
{
"require": {
"tm/error-log-parser": "~1.1"
}
}
使用方法
实例化类
use TM\ErrorLogParser\Parser;
$parser = new Parser(Parser::TYPE_APACHE) // or TYPE_NGINX;
然后解析行
function getLines($file)
{
$f = fopen($file, 'r');
if (!$f) throw new Exception();
while ($line = fgets($f)) {
yield $line;
}
fclose($f);
}
foreach (getLines('/var/log/apache2/error.log') as $line) {
$entry = $parser->parse($line);
}
其中 $entry
包含所有解析数据。对于Apache
stdClass Object (
[date] => "Tue Dec 29 08:14:45 2015"
[type] => "warn"
[client] => "193.158.15.243"
[message] => "mod_fcgid: stderr: PHP Warning: Division by zero in /var/www/kd/app.de/src/Calc.php on line 346, referer: https://www.app.de"
)
对于Nginx
stdClass Object (
[date] => "2011/06/10 13:30:10"
[type] => "error"
[message] => "*1 directory index of "/var/www/ssl/" is forbidden"
[client] => "86.186.86.232"
[server] => "hotelpublisher.com"
[request] => "GET / HTTP/1.1"
[host] => "hotelpublisher.com"
)
否则,您可以使用FormlessParser来解析无格式日志文件
stdClass Object (
[type] => "info"
[message] => "23263#0: *1 directory index of "/var/www/ssl/" is forbidden, client: 86.186.86.232, server: hotelpublisher.com, request: "GET / HTTP/1.1", host: "hotelpublisher.com""
)
贡献
请参阅CONTRIBUTING.md以获取有关如何贡献的信息。