Question

I'm currently using the Poco Logger library in some c++ code. It's running on a server in the US, but even though the system time there is the right timezone, the log files are printing timestamps as GMT.

Is this a configurable Poco setting, or a system setting I need to find? I can't seem to find an answer anywhere!

Possibly useful output below.

Log file sample: 2013-04-03 11:49:32.862 GMT[31015]:Debug:...
Log file format string: pattern = "%Y-%m-%d %H:%M:%S.%i %Z[%P]:%p:%t"

Output from /etc/sysconfig/clock:

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

Output from date: Wed Apr 3 04:57:44 PDT 2013
Output from echo $TZ: America/Los_Angeles

Any ideas greatly appreciated!

Was it helpful?

Solution

The Poco::PatternFormatter class has a property "times" that can be set to "UTC" (default) or "local" (what you're looking for). You can set this in the configuration file, but you'll have to explicitly define a formatter:

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

If you're creating the formatter programmatically, use the setProperty() method:

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

See also: http://pocoproject.org/slides/185-LoggingConfiguration.pdf

OTHER TIPS

In case if anyone is using xml configuration:

<?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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top