how to change date format in "zend_log"

1.5k Views Asked by At

How can I change date format of the Zend_Log?

Now there is date with timestamp added in front of every new log entry:
"2013-01-28T16:47:54+01:00 ... some log message ..."

But I would like to format this date like:
"Y-m-d H:i:s ... some log message ..."

My code looks like this:

class Game_Logger {

    public function __construct($val, $txt = null) {
        $writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../log/log.log');
        $logger = new Zend_Log($writer);
        if (is_array($val)) {
            $output = Zend_Debug::dump($val, null, false);
        } else {
            $output = $val;
        }
        if($txt){
            $output = $txt.' '.$output;
        }
        $logger->info($output);
    }

}
2

There are 2 best solutions below

2
On BEST ANSWER

Probably this will resolve your problem:

$logger->setTimestampFormat("H:i:s");
but something tells me you already figured it out ;).

0
On

For Zend Framework 2 and 3, below code might be help

    $logger = new \Zend\Log\Logger();

    $formatter = new  \Zend\Log\Formatter\Simple();
    $formatter->setDateTimeFormat('Y-m-d'); // as per your choice

    $writer = new \Zend\Log\Writer\Stream('php://output');
    $writer->setFormatter($formatter);
    $logger->addWriter($writer);