Skip to content

Commit

Permalink
more granular timestamps in log
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeph Grunschlag committed Jul 31, 2023
1 parent bcb54fd commit 46bf693
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
11 changes: 11 additions & 0 deletions conduit/data/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions conduit/loggers/loggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

log "github.com/sirupsen/logrus"

"github.com/algorand/conduit/conduit/data"
"github.com/algorand/conduit/conduit/pipeline"
)

Expand All @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions conduit/pipeline/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions conduit/pipeline/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?"

Expand All @@ -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,
)
}

0 comments on commit 46bf693

Please sign in to comment.