enklare-development / laravel-gelf-logger
hedii/laravel-gelf-logger 项目的分支,增加了对 HttpTransport 的支持
5.2.2
2020-06-23 15:50 UTC
Requires
- php: ^7.2
- graylog2/gelf-php: ^1.6
- illuminate/log: >=6
Requires (Dev)
- orchestra/testbench: ^5.0
README
hedii/laravel-gelf-logger 项目的分支,支持 HttpTransport。
指向原始项目的链接
- Github: https://github.com/hedii/laravel-gelf-logger
- Packagist: https://packagist.org.cn/packages/hedii/laravel-gelf-logger
此项目的 Packagist 页面
https://packagist.org.cn/packages/enklare-development/laravel-gelf-logger
Laravel Gelf Logger
一个将 gelf 日志发送到兼容 gelf 的后端(如 graylog)的包。它是 bzikarsky/gelf-php 包的 Laravel 封装。
它使用 Laravel 5.6 中引入的新 Laravel 自定义日志通道。
必须配置一个 gelf 接收器(如 graylog2),以接收使用 GELF UDP 或 TCP 输入的消息。
目录
安装
通过 composer 安装
composer require enklare-development/laravel-gelf-logger
编辑 config/logging.php
添加新的 gelf
日志通道。
return [ 'default' => env('LOG_CHANNEL', 'stack'), 'channels' => [ // You can use the gelf log channel with the stack log channel 'stack' => [ 'driver' => 'stack', 'channels' => ['daily', 'gelf'], ], // other log channels... 'gelf' => [ 'driver' => 'custom', 'via' => \Hedii\LaravelGelfLogger\GelfLoggerFactory::class, // This optional option determines the processors that should be // pushed to the handler. This option is useful to modify a field // in the log context (see NullStringProcessor), or to add extra // data. Each processor must be a callable or an object with an // __invoke method: see monolog documentation about processors. // Default is an empty array. 'processors' => [ \Hedii\LaravelGelfLogger\Processors\NullStringProcessor::class, \Foo\Bar\AnotherProcessor::class, ], // This optional option determines the minimum "level" a message // must be in order to be logged by the channel. Default is 'debug' 'level' => 'debug', // This optional option lets you control if you wish to send "level" and higher // to gelf, or only filter out "level" messages (ex: WARNING, ERROR, CRITICAL or only WARNING and not any other levels) 'filtered_handler' => false, // This optional option determines the channel name sent with the // message in the 'facility' field. Default is equal to app.env // configuration value 'name' => 'my-custom-name', // This optional option determines the system name sent with the // message in the 'source' field. When forgotten or set to null, // the current hostname is used. 'system_name' => null, // This optional option determines if you want the TCP or HTTP transport // for the gelf log messages. Default is UDP 'transport' => 'udp', // This optional option determines the host that will receive the // gelf log messages. Default is 127.0.0.1 'host' => '127.0.0.1', // This optional option determines the api endpoint path that receives // gelf log messages. Default is '/' 'path' => '/', // This optional option determines the port on which the gelf // receiver host is listening. Default is 12201 'port' => 12201, // This optional option determines the maximum length per message // field. When forgotten or set to null, the default value of // \Monolog\Formatter\GelfMessageFormatter::DEFAULT_MAX_LENGTH is // used (currently this value is 32766) 'max_length' => null, // This optional option determines the prefix for 'context' fields // from the Monolog record. Default is null (no context prefix) 'context_prefix' => null, // This optional option determines the prefix for 'extra' fields // from the Monolog record. Default is null (no extra prefix) 'extra_prefix' => null, ], ], ];
用法
一旦修改了 Laravel 日志配置,就可以像使用任何 Laravel 日志通道一样使用 gelf 日志通道 编写日志消息。
示例
// Explicitly use the gelf channel Log::channel('gelf')->debug($message, ['foo' => 'bar']); Log::channel('gelf')->emergency($message, ['foo' => 'bar']); // In case of a stack log channel containing the gelf log channel and stack // configured as the default log channel Log::notice($message, ['foo' => 'bar']); // Using the logger helper logger($message, $context);
测试
composer test
许可
laravel-gelf-logger 在 MIT 许可下发布。有关详细信息,请参阅捆绑的 LICENSE 文件。