From 8f302ac2ed282c50929c29c5dca84ba007c6cf53 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 19 Jul 2026 01:41:55 +0200 Subject: [PATCH 1/7] fix: support custom TimeFormat for console formatter --- format.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/format.go b/format.go index fd9f3da..8780109 100644 --- a/format.go +++ b/format.go @@ -356,7 +356,13 @@ func (c *console) AppendFloat(buf *bytes.Buffer, f float64) { } func (c *console) AppendTime(buf *bytes.Buffer, t time.Time) { - buf.AppendTime(t, time.Kitchen) + switch TimeFormat { + // console formatter defaults to Kitchen format + case TimeFormatUnix: + buf.AppendTime(t, time.Kitchen) + default: + buf.AppendTime(t, TimeFormat) + } } func (c *console) AppendDuration(buf *bytes.Buffer, d time.Duration) { From 5b090a3099f431882394d887e48d632b92306f33 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 19 Jul 2026 16:57:56 +0200 Subject: [PATCH 2/7] fix: add TimeFormatDefault and TimeFormatConsole constants Deprecate TimeFormatUnix and replace it with TimeFormatDefault. --- format.go | 12 +++--------- format_test.go | 4 ++-- logger.go | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/format.go b/format.go index 8780109..c280af0 100644 --- a/format.go +++ b/format.go @@ -110,7 +110,7 @@ func (j *json) AppendFloat(buf *bytes.Buffer, f float64) { func (j *json) AppendTime(buf *bytes.Buffer, t time.Time) { switch TimeFormat { - case TimeFormatUnix: + case TimeFormatDefault: buf.AppendInt(t.Unix()) default: buf.WriteByte('"') @@ -208,7 +208,7 @@ func (l *logfmt) AppendFloat(buf *bytes.Buffer, f float64) { func (l *logfmt) AppendTime(buf *bytes.Buffer, t time.Time) { switch TimeFormat { - case TimeFormatUnix: + case TimeFormatDefault: buf.AppendInt(t.Unix()) default: buf.AppendTime(t, TimeFormat) @@ -356,13 +356,7 @@ func (c *console) AppendFloat(buf *bytes.Buffer, f float64) { } func (c *console) AppendTime(buf *bytes.Buffer, t time.Time) { - switch TimeFormat { - // console formatter defaults to Kitchen format - case TimeFormatUnix: - buf.AppendTime(t, time.Kitchen) - default: - buf.AppendTime(t, TimeFormat) - } + buf.AppendTime(t, TimeFormatConsole) } func (c *console) AppendDuration(buf *bytes.Buffer, d time.Duration) { diff --git a/format_test.go b/format_test.go index 32a5e94..7cb0e3a 100644 --- a/format_test.go +++ b/format_test.go @@ -138,7 +138,7 @@ func TestJsonFormat_Time(t *testing.T) { func TestJsonFormat_TimeFormatted(t *testing.T) { logger.TimeFormat = logger.TimeFormatISO8601 - t.Cleanup(func() { logger.TimeFormat = logger.TimeFormatUnix }) + t.Cleanup(func() { logger.TimeFormat = logger.TimeFormatDefault }) fmtr := logger.JSONFormat() @@ -300,7 +300,7 @@ func TestLogfmtFormat_Time(t *testing.T) { func TestLogfmtFormat_TimeFormatted(t *testing.T) { logger.TimeFormat = logger.TimeFormatISO8601 - t.Cleanup(func() { logger.TimeFormat = logger.TimeFormatUnix }) + t.Cleanup(func() { logger.TimeFormat = logger.TimeFormatDefault }) fmtr := logger.LogfmtFormat() diff --git a/logger.go b/logger.go index 10059e0..7f0b3f8 100644 --- a/logger.go +++ b/logger.go @@ -8,13 +8,24 @@ import ( "time" ) +// TimeFormatDefault is the default format for the time formatter. +// +// TimeFormatDefault is an empty string and uses `time.Unix()`. +var TimeFormatDefault = "" + +// TimeFormatConsole is the default format for the console formatter. +// +// TimeFormatConsole defaults to kitchen time. +var TimeFormatConsole = time.Kitchen + // TimeFormat is the format that times will be added in. // -// TimeFormat defaults to unix time. -var TimeFormat = TimeFormatUnix +// TimeFormat defaults to TimeFormatDefault. +var TimeFormat = TimeFormatDefault // Time formats. const ( + // Deprecated: TimeFormatUnix is deprecated, use TimeFormatDefault instead. TimeFormatUnix = "" TimeFormatISO8601 = "2006-01-02T15:04:05-0700" ) From 3ddd7988b47ce128d20903d448fc98c6393d6bf1 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Mon, 20 Jul 2026 23:41:53 +0200 Subject: [PATCH 3/7] fix: re-add TimeFormatUnix for backwards compatibility --- format.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/format.go b/format.go index c280af0..777eab7 100644 --- a/format.go +++ b/format.go @@ -110,6 +110,7 @@ func (j *json) AppendFloat(buf *bytes.Buffer, f float64) { func (j *json) AppendTime(buf *bytes.Buffer, t time.Time) { switch TimeFormat { + case TimeFormatUnix: case TimeFormatDefault: buf.AppendInt(t.Unix()) default: @@ -208,6 +209,7 @@ func (l *logfmt) AppendFloat(buf *bytes.Buffer, f float64) { func (l *logfmt) AppendTime(buf *bytes.Buffer, t time.Time) { switch TimeFormat { + case TimeFormatUnix: case TimeFormatDefault: buf.AppendInt(t.Unix()) default: From 0a8b929ec888cad608577e2dd214d6f0e03201a4 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Wed, 22 Jul 2026 01:08:23 +0200 Subject: [PATCH 4/7] fix: remove TimeFormatDefault --- format.go | 2 -- logger.go | 7 +------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/format.go b/format.go index 777eab7..c89bdd5 100644 --- a/format.go +++ b/format.go @@ -111,7 +111,6 @@ func (j *json) AppendFloat(buf *bytes.Buffer, f float64) { func (j *json) AppendTime(buf *bytes.Buffer, t time.Time) { switch TimeFormat { case TimeFormatUnix: - case TimeFormatDefault: buf.AppendInt(t.Unix()) default: buf.WriteByte('"') @@ -210,7 +209,6 @@ func (l *logfmt) AppendFloat(buf *bytes.Buffer, f float64) { func (l *logfmt) AppendTime(buf *bytes.Buffer, t time.Time) { switch TimeFormat { case TimeFormatUnix: - case TimeFormatDefault: buf.AppendInt(t.Unix()) default: buf.AppendTime(t, TimeFormat) diff --git a/logger.go b/logger.go index 7f0b3f8..909ae71 100644 --- a/logger.go +++ b/logger.go @@ -8,11 +8,6 @@ import ( "time" ) -// TimeFormatDefault is the default format for the time formatter. -// -// TimeFormatDefault is an empty string and uses `time.Unix()`. -var TimeFormatDefault = "" - // TimeFormatConsole is the default format for the console formatter. // // TimeFormatConsole defaults to kitchen time. @@ -21,7 +16,7 @@ var TimeFormatConsole = time.Kitchen // TimeFormat is the format that times will be added in. // // TimeFormat defaults to TimeFormatDefault. -var TimeFormat = TimeFormatDefault +var TimeFormat = "" // Time formats. const ( From fa74fbef90baf8ec2342fe2eade989b365862267 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Wed, 22 Jul 2026 19:13:30 +0200 Subject: [PATCH 5/7] fix: remove TimeFormatDefault --- format_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/format_test.go b/format_test.go index 7cb0e3a..1802ba9 100644 --- a/format_test.go +++ b/format_test.go @@ -138,7 +138,7 @@ func TestJsonFormat_Time(t *testing.T) { func TestJsonFormat_TimeFormatted(t *testing.T) { logger.TimeFormat = logger.TimeFormatISO8601 - t.Cleanup(func() { logger.TimeFormat = logger.TimeFormatDefault }) + t.Cleanup(func() { logger.TimeFormat = "" }) fmtr := logger.JSONFormat() @@ -300,7 +300,7 @@ func TestLogfmtFormat_Time(t *testing.T) { func TestLogfmtFormat_TimeFormatted(t *testing.T) { logger.TimeFormat = logger.TimeFormatISO8601 - t.Cleanup(func() { logger.TimeFormat = logger.TimeFormatDefault }) + t.Cleanup(func() { logger.TimeFormat = "" }) fmtr := logger.LogfmtFormat() From 39c3d4b1075f50d3b4b4d259aad248b683cec350 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Wed, 22 Jul 2026 19:22:01 +0200 Subject: [PATCH 6/7] fix: remove unneeded comments --- logger.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/logger.go b/logger.go index 909ae71..1f2c921 100644 --- a/logger.go +++ b/logger.go @@ -14,13 +14,10 @@ import ( var TimeFormatConsole = time.Kitchen // TimeFormat is the format that times will be added in. -// -// TimeFormat defaults to TimeFormatDefault. var TimeFormat = "" // Time formats. const ( - // Deprecated: TimeFormatUnix is deprecated, use TimeFormatDefault instead. TimeFormatUnix = "" TimeFormatISO8601 = "2006-01-02T15:04:05-0700" ) From 8b394bfe45dba47f05125863f4b71f110e48fd67 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Wed, 22 Jul 2026 19:24:06 +0200 Subject: [PATCH 7/7] fix: revert removal of TimeFormatUnix --- format_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/format_test.go b/format_test.go index 1802ba9..32a5e94 100644 --- a/format_test.go +++ b/format_test.go @@ -138,7 +138,7 @@ func TestJsonFormat_Time(t *testing.T) { func TestJsonFormat_TimeFormatted(t *testing.T) { logger.TimeFormat = logger.TimeFormatISO8601 - t.Cleanup(func() { logger.TimeFormat = "" }) + t.Cleanup(func() { logger.TimeFormat = logger.TimeFormatUnix }) fmtr := logger.JSONFormat() @@ -300,7 +300,7 @@ func TestLogfmtFormat_Time(t *testing.T) { func TestLogfmtFormat_TimeFormatted(t *testing.T) { logger.TimeFormat = logger.TimeFormatISO8601 - t.Cleanup(func() { logger.TimeFormat = "" }) + t.Cleanup(func() { logger.TimeFormat = logger.TimeFormatUnix }) fmtr := logger.LogfmtFormat()