Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Is it possible to log to database?
  • I have been googling and reading the documentation: http://fuelphp.com/docs/classes/log.html

    But I don't see there is such configuration nor like caches I can choose my cache storage driver or implement my owns. 

    I like how FuelPHP allows me to log messages in different levels, error, warning, etc.  And by setting the logging level, its filters out the message to be log.  As well as the how it is logging down the method which was called.

    So all I want is to redirect the log message that going to log file into my own process, so I can log them into database or redirect to other services.

    Is it possible to do that?
  • HarroHarro
    Accepted Answer
    If you are up to date with your Fuel installation, you can extend the Log class to have Monolog use different handlers or formatters.

    For example, our applications write to syslog in staging and production:

    /**
     * Log class extension.
     *
     * Modifications:
     * - will log to syslog instead of log files if in staging or production
     */
    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();
            }
        }
    }

    You can find Monolog documentation here: https://github.com/Seldaek/monolog
  • @Harro Thanks! I got it working! :)

Howdy, Stranger!

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

In this Discussion