pagevamp / laravel-stack-driver-logger
v1.0.3
2018-03-27 04:46 UTC
Requires
- php: >=5.4
- google/cloud-logging: 1.8.0
- illuminate/support: ^4.0|^5.0
This package is not auto-updated.
Last update: 2024-09-18 21:45:31 UTC
README
Laravel项目Google Cloud Stack Driver错误监控集成。此库为Laravel的日志组件添加了监听器。Laravel的会话信息将被发送到Stack Driver,以及其他一些有用的信息,如'环境'、'服务器'和'会话'。
安装
使用composer安装
composer require pagevamp/laravel-stack-driver-logger
将服务提供者添加到config/app.php文件中的'providers'数组
Pagevamp\Providers\StackDriverLoggerServiceProvider::class,
如果您只想为某些环境启用Stack Driver报告,您可以在AppServiceProvider中条件性地加载服务提供者
public function register() { if ($this->app->environment('production')) { $this->app->register(\Pagevamp\Providers\StackDriverLoggerServiceProvider::class); } }
配置
此包支持通过位于config/services.php的配置文件进行配置。所有配置变量将直接传递到Stack Driver
'stack_driver_logger' => [ 'credentials' => [ 'keyFile' => json_decode(trim(env('GC_LOG_SERVICE_CRED'), "'"), 1), ], 'log_name' => env('GC_LOG_NAME', 'builder-log'), ],
使用方法
要自动监控异常,只需在app/Exceptions/Handler.php的错误处理器中使用Log外观
public function report(Exception $exception) { \Log::error($exception); //Stack Driver parent::report($exception); }
您的其他日志消息也将发送到Stack Driver
\Log::debug('Here is some debug information');
注意:致命异常始终会被发送到Stack Driver。
上下文信息
您可以通过以下方式传递用户信息作为上下文
\Log::error('Something went wrong', [ 'person' => ['id' => 123, 'username' => 'John Doe', 'email' => 'john@doe.com'] ]);
或传递一些额外的信息
\Log::warning('Something went wrong', [ 'download_size' => 3432425235 ]);