From b5158adb510a5370f2db87a3869c9b3a8a17f9e0 Mon Sep 17 00:00:00 2001 From: binwiederhier Date: Sun, 5 Feb 2023 23:53:24 -0500 Subject: [PATCH] Fix linting --- log/event.go | 2 +- log/log.go | 18 ++++++++---------- log/types.go | 1 + 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/log/event.go b/log/event.go index ceebe466..fb02fd0c 100644 --- a/log/event.go +++ b/log/event.go @@ -34,7 +34,7 @@ func newEvent() *Event { // Fatal logs the event as FATAL, and exits the program with exit code 1 func (e *Event) Fatal(message string, v ...any) { e.Field("exit_code", 1).Log(FatalLevel, message, v...) - fmt.Fprintf(os.Stderr, fmt.Sprintf(message+"\n", v...)) // Always output error to stderr + fmt.Fprintf(os.Stderr, message+"\n", v...) // Always output error to stderr os.Exit(1) } diff --git a/log/log.go b/log/log.go index 67191c5e..dcdddcec 100644 --- a/log/log.go +++ b/log/log.go @@ -8,21 +8,19 @@ import ( "time" ) -const ( +// Defaults for package level variables +var ( DefaultLevel = InfoLevel DefaultFormat = TextFormat + DefaultOutput = os.Stderr ) var ( - level = DefaultLevel - format = DefaultFormat - overrides = make(map[string]*levelOverride) - mu = &sync.Mutex{} -) - -var ( - DefaultOutput = os.Stderr - output io.Writer = DefaultOutput + level = DefaultLevel + format = DefaultFormat + overrides = make(map[string]*levelOverride) + output io.Writer = DefaultOutput + mu = &sync.Mutex{} ) // Fatal prints the given message, and exits the program diff --git a/log/types.go b/log/types.go index dd119e4e..75d78179 100644 --- a/log/types.go +++ b/log/types.go @@ -36,6 +36,7 @@ func (l Level) String() string { return "unknown" } +// MarshalJSON converts a level to a JSON string func (l Level) MarshalJSON() ([]byte, error) { return json.Marshal(l.String()) }