fuelphp-storage / fuelphp

FuelPHP framework
http://fuelphp.com
MIT License
274 stars 57 forks source link

CLI/Oil capture the last error on shutdown Event #75

Open polmartinez opened 8 years ago

polmartinez commented 8 years ago

Hi, I can't capture a last error when execute refine command on oil.

in bootstrap.php

\Event::register('shutdown', function() {
    $e = error_get_last();
    // $e is null
});

In all of cases $e is empty when create an Exception on script.

It's possible capture the last error on oil -> refine call for logging? Thanks

WanWizard commented 8 years ago

error_get_last(); doesn't return exception information, only PHP errors. Fuel logs all errors and exceptions by default, is that not enough?

polmartinez commented 8 years ago

it's not enough, I need to centralize errors (at least simple as returned error_get_last) in a function to log them externally, but some errors as in the following example are not logged:

class Queue_Logs extends \Tasks {

    public static function run() {
        throw new \Exception('Exception test');

executing php oil refine queue_logs

How I can get all errors (or at least the fatal) in this event:? \Event::register('shutdown', function() {

WanWizard commented 8 years ago

You can't. There is no PHP method to retrieve the last exception.

The proper way of doing this, is to make a Monolog handler and attach it to the log instance.

polmartinez commented 8 years ago

OK, I want to extends \Core\Log for 1.8 and rewrite logger method for 1.5 version. Thanks

WanWizard commented 8 years ago

Not sure you need to.If you get \Log::instance(), the monolog instance is returned, and you can add your own log handler too it. See https://github.com/Seldaek/monolog/blob/master/doc/02-handlers-formatters-processors.md for a log list of already available handlers.