解决log4c 日志时间与系统时间不符
问题: 在项目中,通过ubuntu交叉编译log4c在ARM上运行时,发现生成的日志文件中log的打印时间与系统时间并不相符,因为时区的原因慢了8个小时。
解决方案: 将log4crc文件中的dated更改为dated_local:
[root@Matrix_061001 dc]
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE log4c SYSTEM "">
<log4c version="1.2.4">
<config>
<bufsize>0</bufsize>
<debug level="2"/>
<nocleanup>0</nocleanup>
<reread>1</reread>
</config>
<!-- root category -->
<category name="root" priority="notice"/>
<category name="mycat" priority="debug" appender="stdout"/>
<category name="file" priority="debug" appender="e2g2231_b01"/>
<!-- default appenders -->
<appender name="stdout" type="stream" layout="basic"/>
<!--logdir 日志输出路径 prefix 文件名 layout 输出格式 (与下方layout对应)-->
<appender name="e2g2231_b01" type="rollingfile" logdir="/home/guest/e2g2231/log" layout="dated_local" rollingpolicy="RollingPolicy"/>
<appender name="stderr" type="stream" layout="dated_local"/>
<appender name="syslog" type="syslog" layout="basic"/>
<!-- default layouts -->
<layout name="basic" type="basic"/>
<layout name="dated_local" type="dated_local"/>
<!--sizewin表示达到最大值后新建日志文件 值由maxsize设定,单位Bytes maxnum为最大文件数目 maxsize=5mb -->
<!--<rollingpolicy name="RollingPolicy" type="sizewin" maxsize="104857600" maxnum="32767" /> -->
<rollingpolicy name="RollingPolicy" type="sizewin" maxsize="10485760" maxnum="5" />
</log4c>
运行结果:
20210715 10:47:09.830 ERROR file- [file:main.c, line:67, function:main]log:5001
20210715 10:47:09.851 ERROR file- [file:main.c, line:67, function:main]log:5012
20210715 10:47:09.872 ERROR file- [file:main.c, line:67, function:main]log:5022
20210715 10:47:09.893 ERROR file- [file:main.c, line:67, function:main]log:5033
20210715 10:47:09.914 ERROR file- [file:main.c, line:67, function:main]log:5043
20210715 10:47:09.935 ERROR file- [file:main.c, line:67, function:main]log:5054
20210715 10:47:09.956 ERROR file- [file:main.c, line:67, function:main]log:5064
20210715 10:47:09.977 ERROR file- [file:main.c, line:67, function:main]log:5075
20210715 10:47:09.998 ERROR file- [file:main.c, line:67, function:main]log:5085
20210715 10:47:10.019 ERROR file- [file:main.c, line:67, function:main]log:5095
[root@Matrix_061001 log]
Thu Jul 15 10:47:12 CST 2021
[root@Matrix_061001 log]
[root@Matrix_061001 log]
[root@Matrix_061001 log]
[root@Matrix_061001 log]
|