pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.42k stars 2.17k forks source link

File Channel Logs in UTC Despite ‘times = local’ #4703

Closed pavledragisic closed 1 month ago

pavledragisic commented 1 month ago

Describe the bug Logging file channel logs using UTC time even though it is configured to use local time by setting logging.channels.file.times = local. For console channel it is not possible to specify times parameter.

To Reproduce Add this configuration and compare times in logs with actual time.

logging.channels.file.class = FileChannel
logging.channels.file.pattern = %Y-%m-%d %H:%M:%S.%i [%p] %s<%I>: %t
logging.channels.file.path = ${application.dir}log/${application.baseName}.log
logging.channels.file.rotation = daily
logging.channels.file.archive = number
logging.channels.file.purgeCount = 10
logging.channels.file.times = local

Expected behavior When logging.channels.file.times = local is configured, timestamps in log file should be using local time. Also times parameter should be supported in console channel. Currently workaround this issue is to use PatternFormatter. Example configuration:

logging.channels.file.class = FileChannel
logging.channels.file.path = /var/log/devs/${application.baseName}.log
logging.channels.file.formatter.class = PatternFormatter
logging.channels.file.formatter.pattern = %Y-%m-%d %H:%M:%S.%i [%p] %s<%I>: %t
logging.channels.file.formatter.times = local

logging.channels.file.rotation = daily
logging.channels.file.archive = number
logging.channels.file.purgeCount = 10

logging.channels.console.class = ColorConsoleChannel
logging.channels.console.formatter.class = PatternFormatter
logging.channels.console.formatter.pattern = %Y-%m-%d %H:%M:%S.%i [%p] %s<%I>: %t
logging.channels.console.formatter.times = local
obiltschnig commented 1 month ago

Check the documentation. The times parameter controls log rotation. To specify a local time for the timestamp written to the logfile, use the %L format specifier or the times property of the PatternFormatter.

    /// Using the "times" property it is possible to specify
    /// time mode for the day/time based rotation. The following values
    /// for the "times" property are supported:
    ///
    ///   * utc:        Rotation strategy is based on UTC time (default).
    ///   * local:      Rotation strategy is based on local time.

In fact, the FileChannel has no control over how the timestamp gets written. This is the business of the formatter.