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

How to log all php errors into day by day separated folders?

At first, how to dump with phalcon all php errors into the log directory?



98.9k

Add this to your public/index.php, first remove the try/catch:

set_exception_handler(function($e) {

    $directory = '../app/logs/' . date('Ym');
    if (!is_dir($directory)) {
        mkdir($directory, 0777, true);
    }

    file_put_contents($directory . '/error-log' . date('d') . '.txt' ,
        $e->getMessage() . PHP_EOL .
        print_r($e->getTrace(), true) . PHP_EOL .
        print_r($_POST, true)         . PHP_EOL .
        print_r($_GET, true)          . PHP_EOL .
        print_r($_SERVER, true),
    FILE_APPEND);

});