Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writer to log date / time in conistent format like in other places. #1412

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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