Adds a mu-plugin that register a Monolog handler to send exception to a Graylog channel.
- Bedrock
- Composer
- PHP 7.3 or greater
- Wordpress
Require this package with Composer:
composer require exolnet/wp-graylog
Define the following PHP constants in your config/application.php
file:
/**
* wp-graylog
*
* Here you may configure the Graylog channel for your application. Behind the
* scene, it uses the Monolog PHP logging library.
*/
Config::define('GRAYLOG_TRANSPORT', env('GRAYLOG_TRANSPORT'));
Config::define('GRAYLOG_HOST', env('GRAYLOG_HOST'));
Config::define('GRAYLOG_PORT', env('GRAYLOG_PORT'));
Config::define('GRAYLOG_LEVEL', env('GRAYLOG_LEVEL'));
Then, update your .env
to add GRAYLOG_HOST
environment variable:
GRAYLOG_HOST=localhost
Once installed, errors occurring in your code with a level higher or equals to the GRAYLOG_LEVEL
will be sent to
the specified Graylog instance. You’ll then be able to centralize all your logs in one place.
The following transports are supported: UDP
, TCP
, SSL
, HTTP
and HTTPS
. Select the transport accordingly to
your Graylog set up using the GRAYLOG_TRANSPORT
configuration. By default, the UDP
transport is used.
The default path for HTTP
and HTTPS
transports is /gelf
. This value can be configured using the GRAYLOG_PATH
configuration.
Config::define('GRAYLOG_PATH', env('GRAYLOG_PATH', '/gelf'));
By default, the blog name is used as the application name, but you can overwrite it with the variable GRAYLOG_APP
:
Config::define('GRAYLOG_APP', 'custom-app-name');
By default, if a GRAYLOG_HOST
is configured, a PHP error handler will be configured to send all errors to Graylog.
This behaviour can be disabled by configuring the following environment variable:
Config::define('GRAYLOG_INITIALIZE_ERROR_HANDLER', false);
You can either capture a caught exception or capture the last error:
try {
$this->functionFailsForSure();
} catch (\Throwable $exception) {
\Exolnet\Wordpress\Graylog\WpGraylog::captureException($exception);
}
// OR
\Exolnet\Wordpress\Graylog\WpGraylog::captureLastError();
To run PHPUnit tests, please use:
composer test
Please see CONTRIBUTING and CODE OF CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Copyright © eXolnet. All rights reserved.
This code is licensed under the MIT license. Please see the license file for more information.