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?



85.0k

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);

});