johndodev/jlog-bundle
Composer 安装命令:
composer require johndodev/jlog-bundle
包简介
Easy logging.
README 文档
README
Installation
composer require johndodev/jlog-bundle
Configuration
.env
JLOG_API_KEY=your_api_key
config/packages/jlog.yaml
jlog: project_api_key: '%env(JLOG_API_KEY)%' enable_exception_listener: true ignore_exceptions: - Symfony\Component\HttpKernel\Exception\NotFoundHttpException # See chapter about logging commands console_channel: console
monolog.yaml
You need to use the buffer handler en amont.
See https://github.com/symfony/monolog-bundle/blob/master/DependencyInjection/Configuration.php#L139
for configuration options.
Ex :
monolog: channels: - deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists - command # same name as jlog.console_channel ... handlers: buffer: type: buffer handler: jlog level: debug # or whatever channels: ["app"] # or whatever jlog: type: service id: jlog.monolog_handler
Usage
Logging commands
Extends Johndodev\JlogBundle\Console\LoggableOutputCommand in your command you want to log.
The start and end of commands will be logged in Jlog, in the channel you configured, with the output as metadata.
Logging exceptions
Unhandled exceptions are already logged (if enabled in config). You can still manually log them as usual, with monolog :
try { // ... } catch (\Exception $e) { $this->logger->error('lorem ipsum...', [ 'exception' => $e->getMessage() ]); }
Logging messages
With monologer, as usual.
It is recommanded to use placeholder, especially for errors which triggers notifications, because the message is used for signature for unique notification.
$this->logger->error('bla bla: {error}', [ 'error' => $e->getMessage() ]);
统计信息
- 总下载量: 358
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-07