oumartraore / log-reader
A library to get logs from file.
dev-master
2021-02-01 22:02 UTC
Requires
This package is auto-updated.
Last update: 2025-03-29 00:53:26 UTC
README
Installation
Using composer
In your project, call bash composer require oumartraore/log-reader
.
Usage
Basic Usage
use OumarTraore\LogReader\LogService; $path = '...'; $logService = new LogService(); $logService->getLogsFromFile($path);
Paginate
use OumarTraore\LogReader\LogService; $path = '...'; $logService = new LogService(); $logFilterDto = new LogFilterDto(); $logFilterDto->setDirection(LogFilterDto::DIRECTION_BEFORE); // or LogFilterDto::DIRECTION_AFTER $logFilterDto->setLimit(25); $logFilterDto->setOffset(50); $logService->getLogsFromFile($path, $logFilterDto);
With Filter
You can filter logs by:
- channels
- levels
- date
use OumarTraore\LogReader\LogService; $path = '...'; $logService = new LogService(); $logFilterDto = new LogFilterDto(); $logFilterDto->setChannels(['channel_1', 'channel_2']); $logFilterDto->setLevels(['level_1', 'level_2']); $logFilterDto->setDateFrom(new \DateTime('2021-01-01 10:10:45')); $logFilterDto->setDateTo(new \DateTime('2021-01-01 12:10:45')); $logService->getLogsFromFile($path, $logFilterDto);
With a custom pattern
use OumarTraore\LogReader\LogService; $path = '...'; $logService = new LogService(); $pattern = '/\[(?P<date>.*)\] \[(?P<logger>[\w-]+)\] \[(?P<level>\w+)\]: (?P<message>[^\[\{]+) (?P<context>[\[\{].*[\]\}]) (?P<extra>[\[\{].*[\]\}])/'; $logService->getLogsFromFile($path, null, $pattern);