revosystems / google-cloud
将日志和报告发送到 Google Cloud 服务
2.0.0
2024-02-06 11:44 UTC
Requires
- php: ^8.1
- google/cloud-error-reporting: ^0.22
- psr/log: ^3.0
This package is auto-updated.
Last update: 2024-09-06 13:10:10 UTC
README
安装
- Composer
composer require revosystems/google-cloud
- 配置
在 logging.php 文件中,向 channels 数组添加以下自定义频道
'google' => [
'driver' => 'custom',
'via' => Revosystems\GoogleCloud\Logger::class,
],
并在 stack 频道驱动程序中声明它
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'google'],
'ignore_exceptions' => false,
],
您还可以将错误发送到 Google,通过在项目的异常处理器中添加 ErrorReport::report($e)
class Handler extends ExceptionHandler
public function report(\Throwable $e)
{
if (! $this->shouldReport($e)) {
return;
}
parent::report($e);
Revosystems\GoogleCloud\ErrorReporter::report($e);
}
最后,您只需在 .env 文件中声明配置变量即可
GOOGLE_CLOUD_PROJECT=<google-cloud-project-id>
GOOGLE_CLOUD_PROJECT_NAME=<without spaces, if not declared will use app('name')>
GOOGLE_CLOUD_PROJECT_VERSION=<ex: 1.0 If not declared will use app.version or 1.0 by default>
GOOGLE_APPLICATION_CREDENTIALS=<path to your service-account.json file>
除此之外,您还需要在 config/filesystems.php 中配置您的 Google Cloud 文件系统
'gcs' => [
'driver' => 'gcs',
'project_id' => env('GOOGLE_CLOUD_PROJECT'),
'project_name' => env('GOOGLE_CLOUD_PROJECT_NAME', config('app.name', <default app name>)),
'project_version' => env('GOOGLE_CLOUD_PROJECT_VERSION', config('app.version', '1.0')),
'key_file' => env('GOOGLE_APPLICATION_CREDENTIALS')
],