【问题标题】:Poco using wrong timezonePoco 使用错误的时区
【发布时间】:2013-04-03 11:57:16
【问题描述】:

我目前在一些 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

任何想法都非常感谢!

【问题讨论】:

    标签: timezone poco-libraries


    【解决方案1】:

    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

    【讨论】:

      【解决方案2】:

      如果有人使用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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-01
        • 2020-03-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多