bugsnag / bugsnag-psr-logger
Official Bugsnag PHP PSR Logger.
Installs: 23 549 080
Dependents: 2
Suggesters: 0
Security: 0
Stars: 305
Watchers: 32
Forks: 8
Open Issues: 1
Requires
- php: >=8.0
- bugsnag/bugsnag: ^3.10
- psr/log: ^2.0|^3.0
Requires (Dev)
- graham-campbell/testbench-core: ^1.1
- mockery/mockery: ^1.3.1
- phpunit/phpunit: ^9.4.3
README
The Bugsnag PHP PSR logger is an implementation of the Fig PSR logging standard that provides a standard interface to logging to Bugsnag.
Getting Started
Installing
Add bugsnag/bugsnag-psr-logger
to your composer.json
.
Configuring
This library provides a logger interface but uses the bugsnag-php notifier library as a base. All configuration should be performed as described in the official bugsnag-php documentation.
Using the Loggers
The library provides two loggers, BugsnagLogger
and MultiLogger
.
BugsnagLogger
will automatically send a notification to Bugsnag if it receives a message with a severity higher than info
. This will allow you to notify of any handled exceptions through interfacing the logger directly with the framework you are using. Ensure that the logger can communicate with the bugsnag-php
library by passing the client
object into it on creation.
$bugsnag = Bugsnag\Client::make('YOUR-API-KEY-HERE'); $logger = new Bugsnag\PsrLogger\BugsnagLogger($bugsnag); # Will send a notification to bugsnag $logger->error('An error occurred');
If you wish to use a separate logger alongside BugsnagLogger
you will need to use MultiLogger
. By passing it an array of Logger
objects on construction, MultiLogger
will call into each passed Logger
in turn when a message is logged.
$logger = new Bugsnag\PsrLogger\BugsnagLogger($bugsnag); $mySecondLogger = new Logger(); $multiLogger = new Bugsnag\PsrLogger\MultiLogger([$logger, $mySecondLogger]); # Will log to $mySecondLogger and send a notification to bugsnag through $logger $multiLogger->error('An error occurred');
The default level at which logs will be sent to Bugsnag is Psr\Log\LogLevel::NOTICE
. This can be overridden using the setNotifyLevel
function:
$logger = new Bugsnag\PsrLogger\BugsnagLogger($bugsnag); # Will not send a notification to bugsnag by default $logger->info('Some interesting information'); $logger->setNotifyLevel(Psr\Log\LogLevel::INFO); # Will send a notification to bugsnag $logger->info('Some more interesting information');
For more information on integrating the loggers into specific frameworks see the individual setup information found in the bugsnag-php documentation.
Contributing
All contributors are welcome! For information on how to build, test and release
bugsnag-psr-logger
, see our contributing guide. Feel free
to comment on existing issues
for clarification or starting points.
License
The Bugsnag PSR logger is free software released under the MIT License. See LICENSE.txt for details.