diff --git a/format.go b/format.go index 4e8e160..8b71e4f 100644 --- a/format.go +++ b/format.go @@ -12,10 +12,15 @@ import ( ) const ( - timeFormat = "2006-01-02T15:04:05-0700" - termTimeFormat = "01-02|15:04:05" - floatFormat = 'f' - termMsgJust = 40 + DefTimeFormat = "2006-01-02T15:04:05-0700" + DefTermTimeFormat = "01-02|15:04:05" + floatFormat = 'f' + termMsgJust = 40 +) + +var ( + TimeFormat = DefTimeFormat + TermTimeFormat = DefTermTimeFormat ) // Format is the interface implemented by StreamHandler formatters. @@ -64,9 +69,9 @@ func TerminalFormat() Format { b := &bytes.Buffer{} lvl := strings.ToUpper(r.Lvl.String()) if color > 0 { - fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %s ", color, lvl, r.Time.Format(termTimeFormat), r.Msg) + fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %s ", color, lvl, r.Time.Format(TermTimeFormat), r.Msg) } else { - fmt.Fprintf(b, "[%s] [%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Msg) + fmt.Fprintf(b, "[%s] [%s] %s ", lvl, r.Time.Format(TermTimeFormat), r.Msg) } // try to justify the log output for short messages @@ -180,7 +185,7 @@ func formatShared(value interface{}) (result interface{}) { switch v := value.(type) { case time.Time: - return v.Format(timeFormat) + return v.Format(TimeFormat) case error: return v.Error() @@ -216,7 +221,7 @@ func formatLogfmtValue(value interface{}) string { // Performance optimization: No need for escaping since the provided // timeFormat doesn't have any escape characters, and escaping is // expensive. - return t.Format(timeFormat) + return t.Format(TimeFormat) } value = formatShared(value) switch v := value.(type) {