rs / zerolog

Zero Allocation JSON Logger
MIT License
10.62k stars 572 forks source link

Console output "0216-15:28:03+08:05" #524

Open luxinxinxin opened 1 year ago

luxinxinxin commented 1 year ago

When I set zerolog.TimeFieldFormat = "0102-15:04:05Z07" and zerolog.ConsoleWriter.TimeFormat = "0102-15:04:05Z07:00" ,the console output "0216-15:28:03+08:05" at 20230216-15:22:20+08. I try to find the cause of the problem, I found the function consoleDefaultFormatTimestamp in console.go line 340, it use "0216-15:28:03+08" as an argument to the function time.Parse(),so it considers "0216-15:28:03+08" equal to "0000-0216-15:28:03+08". I think it should use a variable of type time.Time as parameter not string. but I can avoid this problem when I set zerolog.TimeFieldFormat = "060102-15:04:05Z07" . I find this problem on linux(ubuntu18.04.1) system, but windows system looks normal. On windows. the console output "0216-15:22:20+08:00" at 20230216-15:22:20+08.

mitar commented 1 year ago

I think your problem is that you are using TimeFieldFormat without a year field. This leads to many issues. TimeFieldFormat is used for JSON field. There you should keep year. If you want to change how dates are written do the console only, do not change TimeFieldFormat.