From ea5e7c9e1cd7462e07842f394ca0c3b8d68dce45 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sun, 27 Feb 2022 10:37:22 -0700 Subject: [PATCH] make time formatting be optional --- main.go | 17 ++++++++++------- pmux-example.yml | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index e14ee50..8d77828 100644 --- a/main.go +++ b/main.go @@ -135,11 +135,18 @@ func (l *logger) println(line string) { l.l.Lock() defer l.l.Unlock() + if l.timeFmt != "" { + fmt.Fprintf( + l.outBuf, + "%s %c ", + time.Now().Format(l.timeFmt), + l.sep, + ) + } + fmt.Fprintf( l.outBuf, - "%s %c %s%s%c %s\n", - time.Now().Format(l.timeFmt), - l.sep, + "%s%s%c %s\n", l.pname, strings.Repeat(" ", int(*l.maxPNameLen+1)-len(l.pname)), l.sep, @@ -167,10 +174,6 @@ type config struct { func (cfg config) init() (config, error) { - if cfg.TimeFormat == "" { - cfg.TimeFormat = "2006-01-02T15:04:05.000Z07:00" - } - if len(cfg.Processes) == 0 { return config{}, errors.New("no processes defined") } diff --git a/pmux-example.yml b/pmux-example.yml index 8f67e94..009ea1a 100644 --- a/pmux-example.yml +++ b/pmux-example.yml @@ -3,6 +3,8 @@ # timeFormat defines the formatting of timestamps. See # https://pkg.go.dev/time#pkg-constants for more info on how the formatting # string works. +# +# If timeFormat isn't set then the time is not included in each log line. timeFormat: "2006-01-02T15:04:05.000Z07:00" # processes is the only required field, it must have at least one process