Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

about

I have a question, use Phalcon\Logger\Adapter\File , the log increase to a quantity, whether it will generate another log file? i don't try. thanks



5.9k

it will append to end of file but you can rotate log file each hour/day/month etc



2.3k
Accepted
answer
edited Nov '14

You can use a logic like this

<?php
        $loggerPath = "../app/logs/sql.log";

        // size greater than 3 MB
        if (filesize($loggerPath) > 3000000) {

            // increment older log files
            for ($i = 10; $i > 0; $i--) {

                if (file_exists('../app/logs/sql.' . $i . '.log')) {
                    rename('../app/logs/sql.' . $i . '.log', '../app/logs/sql.' . ($i + 1) . '.log');
                }
            }

            // delete eleventh file if it exists
            if (file_exists('../app/logs/sql.11.log')) {
                unlink('../app/logs/sql.11.log');
            }

            rename($loggerPath, '../app/logs/sql.1.log');
        }

        $logger = new FileLogger("../app/logs/sql.log", array('mode' => 'a'));

This is only a quick test implementation ;-) It will keep 10 files with max 3 MB size.

If this is on a Linux system, the proper way to rotate the logs would be to use the log rotate daemon.

I thought Phalcon\Logger\Adapter\File own mechanism . do not written the logic of file size.. thanks



2.9k

@YangHuiFor - Do you still need something like this? I'm actually developing a logger that does this (ie: emulates log rotate daemon) with some colour coding so you can easily tail -f and identify errors much easier.

I'll be releasing it on GitHub soon, but will announce it on the forums anyways.