From a0ab9f6935ea240e4d77d32604f52c8fba812740 Mon Sep 17 00:00:00 2001 From: Zeph Grunschlag Date: Tue, 1 Aug 2023 09:49:01 -0500 Subject: [PATCH] more granular timestamps in logs (#129) --- conduit/data/config.go | 6 ++++++ conduit/loggers/loggers.go | 2 ++ conduit/pipeline/logging.go | 3 +++ conduit/pipeline/logging_test.go | 7 ++++--- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/conduit/data/config.go b/conduit/data/config.go index 62668003..e82b9158 100644 --- a/conduit/data/config.go +++ b/conduit/data/config.go @@ -10,6 +10,12 @@ 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" + ConduitTimeFormat = time.RFC3339Nano +) + // 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, + ) }