Pushes Craft CMS logs to Better Stack through a real Yii 2 log target.
- Native Yii 2 log target that is fully customisable
- All errors and warnings for each request are sent
- Plugin settings can be defined in the CP or with a config file
- Calls for
Craft::error()andCraft::warning()are sent and categorized
This plugin requires Craft CMS 5.5.0 or later, and PHP 8.2 or later.
You can install this plugin from the Plugin Store or with Composer.
Go to the Plugin Store in your project’s Control Panel and search for “Better Stack Logger”. Then press “Install”.
Open your terminal and run the following commands:
# go to the project directory
cd /path/to/my-project.test
# tell Composer to load the plugin
composer require arcane-web-design/craft-better-stack-logger
# tell Craft to install the plugin
./craft plugin/install better-stack-loggerYou can configure the plugin settings directly in the CP or you can create a config/better-stack-logger.php config file
with the following contents. Make sure to update your .env environment file accordingly with the correct values.
<?php
use craft\helpers\App;
return [
'*' => [
'enabled' => false,
'sourceToken' => App::env('BETTERSTACK_SOURCE_TOKEN'),
'levels' => ['error', 'warning'],
'logVars' => [],
'exceptCodes' => [403, 404],
],
'staging' => [
'enabled' => true,
],
'production' => [
'enabled' => true,
],
];This plugin adds a native Yii 2 log target that is an instance of the yii\log\Target class. See the Yii 2 API Documentation for all available properties.
This parameter is a boolean that indicates whether this log target is enabled.
This required parameter is a string given to you by Better Stack when configuring a new log source.
This required parameter is an array of log level names that this log target is interested in. Defaults to error and
warning. We have intentionally disabled reporting info, profile and debug log levels to Better Stack because Craft
generates a lot of messages for these log levels.
This optional parameter is an array of global arrays that will be sent to Better Stack. Defaults to []. We have intentionally disabled sending logVars to Better Stack because Craft
generates a lot of messages for these. In production, you may want these to help investigate bugs.
This optional parameter is an array of HTTP status codes that this log target is NOT interested in. This is a shortcut
for the except parameter to make it easier. Defaults to 403 and 404, meaning that yii\web\HttpException:403 and
yii\web\HttpException:404 categories will be excluded from the categories parameter.
