Skip to content

Commit

Permalink
Writer to log date / time in conistent format like in other places.
Browse files Browse the repository at this point in the history
  • Loading branch information
aphorise committed Sep 2, 2020
1 parent 7a46831 commit 4caec4d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"strings"
"time"

"github.com/hashicorp/go-syslog"
"github.com/hashicorp/logutils"
Expand All @@ -14,6 +15,14 @@ import (
// Levels are the log levels we respond to=o.
var Levels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERR"}

type logWriter struct {
}

// writer to output date / time in a standard format
func (writer logWriter) Write(bytes []byte) (int, error) {
return fmt.Print(time.Now().Format("2006-01-02T15:04:05.000Z0700") + " " + string(bytes))
}

// Config is the configuration for this log setup.
type Config struct {
// Level is the log level to use.
Expand All @@ -33,6 +42,9 @@ type Config struct {
func Setup(config *Config) error {
var logOutput io.Writer

log.SetFlags(0)
log.SetOutput(new(logWriter))

// Setup the default logging
logFilter := NewLogFilter()
logFilter.MinLevel = logutils.LogLevel(strings.ToUpper(config.Level))
Expand Down Expand Up @@ -60,8 +72,8 @@ func Setup(config *Config) error {
logOutput = io.MultiWriter(logFilter)
}

log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.LUTC)
log.SetOutput(logOutput)
log.SetOutput(new(logWriter))

return nil
}
Expand Down

0 comments on commit 4caec4d

Please sign in to comment.