From 46bf693a4cb8e87b38bd24ba80a3829c50e5ebbc Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Sun, 30 Jul 2023 22:06:49 -0500 Subject: [PATCH] more granular timestamps in log --- conduit/data/config.go | 11 +++++++++++ conduit/loggers/loggers.go | 2 ++ conduit/pipeline/logging.go | 3 +++ conduit/pipeline/logging_test.go | 7 ++++--- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/conduit/data/config.go b/conduit/data/config.go index 62668003..7376ce69 100644 --- a/conduit/data/config.go +++ b/conduit/data/config.go @@ -10,6 +10,17 @@ import ( yaml "gopkg.in/yaml.v3" ) +const ( + // ConduitTimeFormat is the time format used by conduit's logger. + // time.RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00" + // Compare with logrus' default time format: + // time.RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" + ConduitTimeFormat = time.RFC3339Nano + + // Unfortunately, variations on this theme didn't work: + // ConduitTimeFormat = "Mon, 02 Jan 2006 15:04:05.123456789 -0700" +) + // DefaultConfigBaseName is the default conduit configuration filename without the extension. var DefaultConfigBaseName = "conduit" diff --git a/conduit/loggers/loggers.go b/conduit/loggers/loggers.go index 77c8fd02..31b1979d 100644 --- a/conduit/loggers/loggers.go +++ b/conduit/loggers/loggers.go @@ -8,6 +8,7 @@ import ( log "github.com/sirupsen/logrus" + "github.com/algorand/conduit/conduit/data" "github.com/algorand/conduit/conduit/pipeline" ) @@ -16,6 +17,7 @@ func MakeThreadSafeLoggerWithWriter(level log.Level, writer io.Writer) *log.Logg formatter := pipeline.PluginLogFormatter{ Formatter: &log.JSONFormatter{ DisableHTMLEscape: true, + TimestampFormat: data.ConduitTimeFormat, }, Type: "Conduit", Name: "main", diff --git a/conduit/pipeline/logging.go b/conduit/pipeline/logging.go index 40a628c9..0a8e31d6 100644 --- a/conduit/pipeline/logging.go +++ b/conduit/pipeline/logging.go @@ -2,6 +2,8 @@ package pipeline import ( log "github.com/sirupsen/logrus" + + "github.com/algorand/conduit/conduit/data" ) // PluginLogFormatter formats the log message with special conduit tags @@ -23,6 +25,7 @@ func makePluginLogFormatter(pluginType string, pluginName string) PluginLogForma return PluginLogFormatter{ Formatter: &log.JSONFormatter{ DisableHTMLEscape: true, + TimestampFormat: data.ConduitTimeFormat, }, Type: pluginType, Name: pluginName, diff --git a/conduit/pipeline/logging_test.go b/conduit/pipeline/logging_test.go index dcff8aa0..c2beb10c 100644 --- a/conduit/pipeline/logging_test.go +++ b/conduit/pipeline/logging_test.go @@ -10,7 +10,6 @@ import ( // TestPluginLogFormatter_Format tests the output of the formatter while pondering philosophy func TestPluginLogFormatter_Format(t *testing.T) { - pluginType := "A Question" pluginName := "What's in a name?" @@ -29,6 +28,8 @@ func TestPluginLogFormatter_Format(t *testing.T) { bytes, err := pluginFormatter.Format(entry) assert.Nil(t, err) str := string(bytes) - assert.Equal(t, str, "{\"__type\":\"A Question\",\"_name\":\"What's in a name?\",\"level\":\"info\",\"msg\":\"That which we call a rose by any other name would smell just as sweet.\",\"time\":\"0001-01-01T00:00:00Z\"}\n") - + assert.Equal(t, + "{\"__type\":\"A Question\",\"_name\":\"What's in a name?\",\"level\":\"info\",\"msg\":\"That which we call a rose by any other name would smell just as sweet.\",\"time\":\"0001-01-01T00:00:00Z\"}\n", + str, + ) }