Code Monkey home page Code Monkey logo

bugsnag-psr-logger's Introduction

Bugsnag PHP PSR Logger

StyleCI Status

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.

bugsnag-psr-logger's People

Contributors

alfredbez avatar ankurk91 avatar cawllec avatar grahamcampbell avatar imjoehaines avatar kattrali avatar martin308 avatar snmaynard avatar tomlongridge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bugsnag-psr-logger's Issues

PHP Fatal error: Declaration of Bugsnag\PsrLogger\BugsnagLogger::log

Describe the bug

after I upgreded to PHP 8 bugsnag is not working

PHP Fatal error: Declaration of Bugsnag\PsrLogger\BugsnagLogger::log(mixed $level, Stringable|string $message, array $context = []): void must be compatible with PsrExt\Log\LoggerInterface::log($level, $message, array $context = []) in /var/www/default/vendor/bugsnag/bugsnag-psr-logger/src/BugsnagLogger.php on line 66

Environment

  • Bugsnag version: v2.24.0
  • PHP version: 8.0
  • Composer version: 2.3.5
  • Laravel version: 8.83.13
  • PSR-3 implementation and version: 2.0.0

Details

I cannot upgrade to V3 because:

symfony/console
"conflict": { "psr/log": ">=3",

It send the metadata/context in a wrong format

Currently bugsnag can't handle multidimensional array/object as metadata/custom data.

So this one is fine:

Log::error('whatever', ['error' => 'single']);

But this one will miss the error2:

Log::error('whatever', ['error' => 'single', 'error2' => ['error2.1' => 'multi']]);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.