We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Log flash messages?

Is there some smart way to send flash messages into log file?

$this->flash->error( "Some error message!" );

$this->logger->error( "Some error message!" );

I could extend \Phalcon\Flash\Direct::message() function, call DI, find logger and log it. Could events help in this case?



1.6k
Accepted
answer
edited Feb '16

I think the easiest solution is to create a new DI service:

$di->setShared("flashLoggerCombo", new FlashLoggerCombo() );

class FlashLoggerCombo extends \Phalcon\Mvc\User\Plugin
{
    public function error($message)
    {
        $this->logger->error($messsage);
        $this->flash->error($message);
    }

    // ...
}