服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > magento教程 >

自定义Magento Log文件时间格式Magento Log Timestamp

时间:2017-03-16 00:39来源:未知 作者:最模板 点击:
在Magento开发中我们经常会使用Mage::log()函数在/var/log/system.log文件中添加一些Log记录,比如 Mage::log(some message...); // 当前时间是北京时间 2017-11-28 12:00:00 将添加 2017-11-28T04:00:00+00:00 DEBUG
在Magento开发中我们经常会使用Mage::log()函数在/var/log/system.log文件中添加一些Log记录,比如
Mage::log('some message...'); // 当前时间是北京时间 2017-11-28 12:00:00
将添加
2017-11-28T04:00:00+00:00 DEBUG (7): some message...
我们发现系统用的是date('c')这样的时间格式,且用的是UTC时间,这对我们阅读Log不是非常方便,如果我们希望把Log的时间格式设置为date('Y-m-d H:i:s')且时区设置为北京时间,可以做以下修改:打开/app/Mage.php 在Mage类的log()函数中,将
$loggers[$file]->log($message, $level);
修改为:
$loggers[$file]->setTimestampFormat('Y-m-d H:i:s'); // 设置Log的时间格式
$currentTimezone = @date_default_timezone_get(); // 保存当前的时区设置
@date_default_timezone_set('Asia/Shanghai'); // 设置为北京时间
$loggers[$file]->log($message, $level); // 记录Log
@date_default_timezone_set($currentTimezone); // 恢复以前设置的时区
修改之后,Log的格式将变为:
2017-11-28 12:00:00 DEBUG (7): some message...
 
(责任编辑:最模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------