exolnet / wp-graylog
Adds a mu-plugin that register a Monolog handler to send exception to a Graylog channel.
Installs: 3 226
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 4
Forks: 0
Open Issues: 0
Type:wordpress-muplugin
Requires
- php: ^7.4|^8.0
- graylog2/gelf-php: ^1.6
- monolog/monolog: ^2.3
- myclabs/php-enum: ^1.8.1
Requires (Dev)
- exolnet/phpcs-config: ^1.0
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9.3.3
- squizlabs/php_codesniffer: ^3.6
README
Adds a mu-plugin that register a Monolog handler to send exception to a Graylog channel.
Requirements
- Bedrock
- Composer
- PHP 7.3 or greater
- Wordpress
Installation
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
Usage
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.
Supported Transports
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'));
Application Name
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');
Disable Default Error Handler
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);
Capturing Errors
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();
Testing
To run PHPUnit tests, please use:
composer test
Contributing
Please see CONTRIBUTING and CODE OF CONDUCT for details.
Security
If you discover any security related issues, please email security@exolnet.com instead of using the issue tracker.
Credits
License
This code is licensed under the MIT license. Please see the license file for more information.