如何更改Zend_Log的日期格式?
现在,在每个新日志条目的前面都添加了带有时间戳的日期:
"2013-01-28T16:47:54+01:00 ...一些日志消息..."
但我想将此日期格式化为:
"是的-m-d H:i:s ...一些日志消息..."
我的代码如下所示:
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);
}
}
也许这将解决您的问题:
$logger->setTimestampFormat("H:i:s");
但有些事情告诉我你已经想通了;)。
对于 Zend Framework 2 和 3,下面的代码可能会有所帮助
$logger = new ZendLogLogger();
$formatter = new ZendLogFormatterSimple();
$formatter->setDateTimeFormat('Y-m-d'); // as per your choice
$writer = new ZendLogWriterStream('php://output');
$writer->setFormatter($formatter);
$logger->addWriter($writer);