aainc/newrelic-logger
v0.1.4
2022-03-28 04:43 UTC
Requires
- php: >=5.6
- laravel/framework: ^6.0|^7.0|^8.0|^9.0
- newrelic/monolog-enricher: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- mockery/mockery: ~1.5.0
- phpunit/phpunit: ~9.5.13
This package is not auto-updated.
Last update: 2024-09-23 17:08:48 UTC
README
描述
在 Laravel 上使用 Newrelic Logs 时,用于控制日志输出内容的库。
解析发送到 message 的字符串、数组或异常,并发送到 Newrelic Logs。
要求
- PHP 7.1 或更高版本
- Laravel 5.4 或更高版本
- Newrelic API 密钥
开始使用
安装
composer require aainc/newrelic-logger
初始化
config/logging.php
'stack' => [ 'driver' => 'stack', 'channels' => ['single','newrelic'], 'ignore_exceptions' => false, ], ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'newrelic' => [ 'driver' => 'monolog', 'handler'=> \NewRelic\Monolog\Enricher\Handler::class, 'tap' => [\Aainc\NewrelicLogger\NewRelicLogs::class], 'level' => env('LOG_LEVEL', 'debug'), 'formatter' => 'default', ],
config/aa-newrelic-logger.php
<?php return [ // Minimum log level describing additional information (default:DEBUG) 'log_level' => \Monolog\Logger::DEBUG, // This may be useful if the New Relic PHP agent is not installed, or if you wish to log to a different account or region. // (default:null) 'license_key' => null, // Can use this to log output with server environment variable information. 'extra_data' => [] ];
示例
<?php return [ 'log_level' => \Monolog\Logger::DEBUG, 'license_key' => getenv('NEWRELIC_LICENSE_KEY'), 'extra_data' => [ 'host_name' => getenv('HOST_NAME') ] ];
发送日志
发送文本消息
Log::debug('Send text);
发送数组消息
Log::debug('array', [ 'hoge' => 'fuga', 'hogehoge' => 'fugafuga' ]);
发送异常
Log::debug(new Exception('message');