inquid / yii2-google-debugger
Use Google Cloud Logger into your Yii projects
Package info
github.com/inquid/yii2-google-debugger
Type:yii2-extension
pkg:composer/inquid/yii2-google-debugger
v2
2021-06-04 01:40 UTC
Requires
- google/cloud-logging: ^1.21
- yiisoft/yii2: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Google Debugger for Yii
Use Google Cloud Logger into your Yii projects
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist inquid/yii2-google-debugger "*"
or add
"inquid/yii2-google-debugger": "*"
to the require section of your composer.json file.
Usage
Once the extension is installed, simply generate a service account with Cloud Debugger Agent permissions and configure your target as the following:
'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ 'googleCloud' => [ 'class' => 'inquid\google_debugger\GoogleCloudLogger', 'categories' => ['cat1','cat2'], //Your categories to log 'levels' => ['info', 'trace', 'warning', 'error'], 'except' => ['yii\web\HttpException:*', 'yii\i18n\I18N\*'], 'prefix' => function () { $url = !Yii::$app->request->isConsoleRequest ? Yii::$app->request->getUrl() : null; return sprintf('[%s][%s]', Yii::$app->id, $url); }, 'projectId' => 'project-id', 'loggerInstance' => 'instance-log', 'clientSecretPath' => '../google_credentials.json' //path to your service account credentials ] ], ],
And thats it! log as you may log using Yii
Yii::debug('start calculating average revenue',GoogleCloudLogger::CATEGORY); Yii::warning('Warning'); Yii::info('Info'); Yii::error('Error');
And check them in https://console.cloud.google.com/logs/viewer?project=your_project_id