Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Logging with backtrace
  • Hi!

    Thanks for building this awesome framework. I really enjoy using it.
    My app has been in production for a few months right now and i'm facing some debugging issues. When i'm reading logs I can't always know what was the reason of error/warning/notice. There's not enough info logged. Is it possible to log backtrace, request details and some other useful stuff that would help to debug in production?

    Thnks!
  • HarroHarro
    Accepted Answer
    Fuel uses Monolog (https://github.com/Seldaek/monolog) as it's log processor, through the Log class.

    You can overload the Log class static Initialize() method. Start by copying the existing method. In your overloaded copy, you can change the format string of the line formatter to anything you like, add additional processors, etc.

    The default lineformatter has a public method includeStacktraces(), so simply doing $formatter->
    includeStacktraces() would be enough to add a stack trace to the log.

    For custom logging, you need a custom processor. One of our apps does:

    // load our custom monolog processor
    import('monolog/customprocessor', 'vendor');
    static::$monolog->pushProcessor(new \Monolog\Processor\CustomProcessor(\Input::server()));

    to log $_SERVER data. The custom processor looks this this: http://bin.fuelphp.com/snippet/view/MR

    but you can log anything you want.
  • I tried to $formatter->includeStacktraces() but had no success making logs have stacktraces. I even tried to add this line to core/log.php thinking that overloading core class did not work, still no success.
  • It depends on the version of Monolog in use. The default Monolog included is 1.5.x, which does not include this feature.

    Update to at least 1.12 (I think) in your composer.json and run a "composer update" to make sure you have the correct version.
  • Yes of course i set Monolog version to 1.* in composer.json and updated it. The includeStacktraces method exists but does not work for me, it just does write stacktrace to log.
    I think it's monolog related problem, is it?
  • If the standard functionality doesn't work, you need to create a custom processor, like the one i linked to a few posts back. Then you can wrote to the log whatever you want.

Howdy, Stranger!

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

In this Discussion