theodorejb / iis-log-parser
解析 IIS 日志文件
v1.0.1
2023-09-21 14:40 UTC
Requires
- php: >=8.1
Requires (Dev)
- phpunit/phpunit: ^10.3
- psalm/plugin-phpunit: ^0.18.4
- vimeo/psalm: ^5.15
This package is auto-updated.
Last update: 2024-09-21 16:51:12 UTC
README
此包简化了使用PHP解析IIS日志文件的过程。支持标准的W3C日志文件格式,包括默认字段以及可选的Host字段。
通过Composer安装
composer require theodorejb/iis-log-parser
用法
为要解析的IIS日志文件构建一个SplFileObject
实例。然后调用IISLogFile::getEntries
静态方法,传入该SplFileObject
。这将返回一个生成器,为文件中的每个条目生成一个IISLogEntry
对象。
遍历目录中所有日志文件条目的代码示例
use theodorejb\IISLogParser\IISLogFile; $directory = new \FilesystemIterator('C:/inetpub/logs/LogFiles/W3SVC1'); while ($directory->valid()) { $current = $directory->current(); echo "Processing {$current->getFilename()}\n"; $entries = IISLogFile::getEntries($current->openFile()); foreach ($entries as $entry) { echo "Request to {$entry->uri} occurred on {$entry->date->format(DATE_ATOM)}\n"; } echo "\n"; $directory->next(); }
IISLogEntry
类具有以下公共属性
DateTimeImmutable $date
string $serverIP
string $method
string $uri
string $query
int $serverPort
string $username
string $clientIP
string $useragent
string $referer
string $host
int $statusCode
int $subStatusCode
int $win32StatusCode
int $timeTakenMs
它还有一个公共的getUriExtension()
方法。
必需字段
仅日期和时间日志字段(用于$date
属性)是必需的。如果相关的日志字段不存在,其他属性将设置为空字符串(对于int属性为0)。