Poco使用错误的时区

时间:2013-04-03 11:57:17

标签: timezone poco-libraries

我目前正在使用某些c ++代码中的Poco Logger库。它在美国的服务器上运行,但即使系统时间存在正确的时区,日志文件也会将时间戳打印为GMT。

这是一个可配置的Poco设置,还是我需要找到的系统设置?我似乎无法在任何地方找到答案!

下面可能有用的输出。

日志文件示例:2013-04-03 11:49:32.862 GMT[31015]:Debug:...
日志文件格式字符串:pattern = "%Y-%m-%d %H:%M:%S.%i %Z[%P]:%p:%t"

/etc/sysconfig/clock的输出:

ZONE="America/Los_Angeles"
UTC=true
ARC=false

date的输出:Wed Apr 3 04:57:44 PDT 2013
echo $TZ的输出:America/Los_Angeles

任何想法都非常感谢!

2 个答案:

答案 0 :(得分:6)

Poco :: PatternFormatter类有一个属性“times”,可以设置为“UTC”(默认值)或“local”(您要查找的内容)。 您可以在配置文件中进行设置,但是您必须明确定义格式化程序:

logging.channels.c1.class = FileChannel
logging.channels.c1.path = ${system.tempDir}/sample.log
logging.channels.c1.formatter.class = PatternFormatter
logging.channels.c1.formatter.pattern = %Y-%m-%d %H:%M:%S.%i %Z[%P]:%p:%t
logging.channels.c1.formatter.times = local

如果您以编程方式创建格式化程序,请使用setProperty()方法:

pPatternFormatter->setProperty("times", "local");

另请参阅:http://pocoproject.org/slides/185-LoggingConfiguration.pdf

答案 1 :(得分:0)

如果有人使用xml配置:

<?xml version="1.0" ?>
<Application>
  <logging>
    <channels>
      <logFileChannel>
        <class>FileChannel</class>
        <path>logs/application.log</path>
        <rotation>1 M</rotation>
        <archive>timestamp</archive>
        <compress>true</compress>
        <purgeCount>60</purgeCount>
        <formatter>
          <class>PatternFormatter</class>
          <pattern>%Y-%m-%d %H:%M:%S %p %s [%T] - %t</pattern>
          <times>local</times>
        </formatter>
      </logFileChannel>
    </channels>

    <loggers>
      <root>
        <name></name>
        <channel>logFileChannel</channel>
        <level>debug</level>
      </root>
    </loggers>
  </logging>
</Application>