Coder Social home page Coder Social logo

Integrating logging about whoops HOT 5 CLOSED

filp avatar filp commented on May 21, 2024
Integrating logging

from whoops.

Comments (5)

filp avatar filp commented on May 21, 2024 6

Whoops can easily be integrated with a logger, using a custom handler. Here's a pretty simple example:

$whoops = new Whoops\Run;

// Add some handlers
$whoops->pushHandler(new Whoops\Handler\PrettyPageHandler);
$whoops->pushHandler(new Whoops\Handler\JsonResponseHandler);

// Setup Monolog, for example:
$logger = new Monolog\Logger;
$logger->pushHandler(new Monolog\Handler\StreamHandler("/my/exception.log"));

// Place our custom handler in front of the others, capturing exceptions
// and logging them, then passing the exception on to the other handlers:
$whoops->pushHandler(function ($exception, $inspector, $run) use($logger) {
    $logger->addError($exception->getMessage());
});

from whoops.

unstoppablecarl avatar unstoppablecarl commented on May 21, 2024

@filp the handlers are called in reverse of the order they are added?

from whoops.

filp avatar filp commented on May 21, 2024

@unstoppablecarl That's correct! The idea is to follow the natural structure of an application, where the base/framework has a chance to add the base handlers, and the user/module/component code is able to add more granular behaviors.

from whoops.

maicol07 avatar maicol07 commented on May 21, 2024

@filp your code (#62 (comment)) doesn't work anymore with Monolog 2. Could you update that?

from whoops.

denis-sokolov avatar denis-sokolov commented on May 21, 2024

@maicol07, that’s a comment that’s over 6 years old. :-)

Try pushing the logger handler above the other handlers.

from whoops.

Related Issues (20)

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.