Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Send a notify email when fatal error happens
  • Hello,
    As this discussion http://fuelphp.com/forums/discussion/8622, to modify the view of fatal error in production, copy it to app/views/errors/production.php and change it.
    But in staging mode and production mode, I also need to send an notify email to admin about fatal error detail (and stack trace as it is shown in view of development mode). Write send email code in app/views/errors/production.php or php_fatal_error.php maybe a solution, but this way somehow is not good since it is different from MVC way.
    Is there any better way to handle this? Any help would be appriciated.
  • look in to bugsnag.com
  • You can also use a custom log handler. Monolog has quite a lot of ready-made handlers (https://github.com/Seldaek/monolog/tree/master/src/Monolog/Handler) and you can roll your own pretty easily.
  • @itcan thanks so much for your suggestion, but it's not free solution...

    @wanwizard excuse me for asking more detail,
    Fuel Log class is using StreamHandler as default, so in order to pushHanlder(new xxxHandler()) I need to extending Log from core class, is that right?

    BTW, i see that "write comment" block does not have preview button :p
  • HarroHarro
    Accepted Answer
    Yes.

    If you're on 1.8-dev, it's very easy as the Log class now has an initialize() method you can overload. If you're on 1.7+, you should be able to either backport the Log class, or to upgrade to 1.8-dev.

    Once done, this is an example of a Log class that logs to syslog:

    class Log extends \Fuel\Core\Log
    {
        /**
         * initialize the created the monolog instance
         */
        public static function initialize()
        {
            if (\Fuel::$env == 'staging' or \Fuel::$env == 'production')
            {
                // create the sysloghandler, and activate the handler
                $stream = new \Monolog\Handler\SyslogHandler(\Config::get('application.name'), 'local6');
                $formatter = new \Monolog\Formatter\LineFormatter("%level_name% --> %message%".PHP_EOL, "Y-m-d H:i:s");
                $stream->setFormatter($formatter);
                static::$monolog->pushHandler($stream);
            }
            else
            {
                // use the original file based streamhandler
                parent::initialize();
            }
        }
    }

  • Thanks so much for your help!
  • Bugsnag has a free plan, it's limited but works very well...

    Is there a free plan?
    After your trial is complete you will be downgraded to a limited feature free plan. The free plan includes 2,000 errors a month with a 1 user, 1 project limit.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion