Configure timezone in log time format
chuvanan opened this issue · comments
An Chu commented
Hi @atheriel ,
Is there a way to configure logfmt_log_layout()
(and json_log_layout()
) to recognize timezone as default_log_layout()
? (I have a minimal example as below)
It's confusing me that all these functions use R_fmt_current_time()
to handle timestamp but only default_log_layout()
is aware of timezone.
Thanks,
require("log4r", mask.ok = "debug")
#> Loading required package: log4r
#>
#> Attaching package: 'log4r'
#> The following object is masked from 'package:base':
#>
#> debug
default_layout_logger = logger(appenders = console_appender(layout = default_log_layout()))
logfmt_layout_logger = logger(appenders = console_appender(layout = logfmt_log_layout()))
Sys.setenv(TZ = "Asia/Bangkok") # set my local timezone
Sys.getenv("TZ")
#> [1] "Asia/Bangkok"
Sys.time()
#> [1] "2022-01-17 11:22:38 +07"
info(default_layout_logger, "Default layout")
#> INFO [2022-01-17 11:22:38] Default layout
info(logfmt_layout_logger, message = "Logfmt layout")
#> level=INFO ts=2022-01-17T04:22:38Z message="Logfmt layout"
Aaron Jacobs commented
This is intentional, see cf8fd1a
. Having times represented in a consistent format makes them much easier to consume later, and RFC 3339 is as close to a standard JSON time format as it gets.
One option would be to add a ts_local
field to your logs that uses the local time representation.