noxdk/monolog-journal-handler
最新稳定版本:1.0.4
Composer 安装命令:
composer require noxdk/monolog-journal-handler
包简介
Monolog handler for journald (systemd) written in pure PHP
README 文档
README
Monolog handler for journald (systemd). This package does not depend on a systemd PHP extension.
Logs are being written directly to the journald socket. It uses LineFormatter for message formatting, but with a modified format, in order to remove timestamp from the message.
The formatter can be changed with $handler->setFormatter();
Features
- Support for custom tags (using monolog context/extra fields)
- Multiline log support
- Exception file and line log tags
Installation
Install with composer: composer require noxdk/monolog-journal-handler
Configuration arguments
| Argument | Description | Default value |
|---|---|---|
$path |
The path to the journald socket | /run/systemd/journal/socket |
$level |
The minimum logging level at which this handler will be triggered | Level::DEBUG |
$bubble |
Whether the messages that are handled can bubble up the stack or not | true |
Examples
Simple log entry:
<?php require 'vendor/autoload.php'; use Monolog\Logger; use Noxdk\MonologJournalHandler\JournalHandler; $log = new Logger('MyLogger', [new JournalHandler()]); $log->info('This is logged to the journal');
nov 20 10:08:14 host MyLogger[1]: INFO: This is logged to the journal
Multiple lines:
$log->info("This is logged to the journal\nand contains multiple\nlines");
nov 20 10:08:14 host MyLogger[1]: INFO: This is logged to the journal
and contains multiple
lines
Custom tags (journal entry as trimmed json output):
$log->info('This is logged to the journal with custom tag', [ 'MY_TAG' => 'MyTag', 'ANOTHER_TAG' => "With\nnewlines" ]);
nov 20 10:08:14 host MyLogger[1]: INFO: This is logged to the journal with custom tag {"MY_TAG":"MyTag","ANOTHER_TAG":"With
newlines"}
{
...
"SYSLOG_IDENTIFIER": "MyLogger",
"_HOSTNAME": "host",
"_UID": "1000",
"MY_TAG": "MyTag",
"ANOTHER_TAG": "With\nnewlines",
"MESSAGE": "INFO: This is logged to the journal with custom tag {\"MY_TAG\":\"MyTag\",\"ANOTHER_TAG\":\"With\nnewlines\"} ",
"PRIORITY": "6",
"_CMDLINE": "php test.php",
...
}
Exception log:
$log->error('Some error occurred', [new Exception('Bad something')]);
nov 20 10:08:14 host MyLogger[1]: ERROR: Some error occurred ["[object] (Exception(code: 0): Bad something at /test.php:18)
[stacktrace]
#0 /test.php(13): TestClass->update()
#1 /test.php(22): TestClass->__construct()
#2 {main}
"]
统计信息
- 总下载量: 7.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-20