make time formatting be optional

This commit is contained in:
Brian Picciano 2022-02-27 10:37:22 -07:00
parent 2c5c669c72
commit ea5e7c9e1c
2 changed files with 12 additions and 7 deletions

17
main.go
View File

@ -135,11 +135,18 @@ func (l *logger) println(line string) {
l.l.Lock() l.l.Lock()
defer l.l.Unlock() defer l.l.Unlock()
if l.timeFmt != "" {
fmt.Fprintf(
l.outBuf,
"%s %c ",
time.Now().Format(l.timeFmt),
l.sep,
)
}
fmt.Fprintf( fmt.Fprintf(
l.outBuf, l.outBuf,
"%s %c %s%s%c %s\n", "%s%s%c %s\n",
time.Now().Format(l.timeFmt),
l.sep,
l.pname, l.pname,
strings.Repeat(" ", int(*l.maxPNameLen+1)-len(l.pname)), strings.Repeat(" ", int(*l.maxPNameLen+1)-len(l.pname)),
l.sep, l.sep,
@ -167,10 +174,6 @@ type config struct {
func (cfg config) init() (config, error) { func (cfg config) init() (config, error) {
if cfg.TimeFormat == "" {
cfg.TimeFormat = "2006-01-02T15:04:05.000Z07:00"
}
if len(cfg.Processes) == 0 { if len(cfg.Processes) == 0 {
return config{}, errors.New("no processes defined") return config{}, errors.New("no processes defined")
} }

View File

@ -3,6 +3,8 @@
# timeFormat defines the formatting of timestamps. See # timeFormat defines the formatting of timestamps. See
# https://pkg.go.dev/time#pkg-constants for more info on how the formatting # https://pkg.go.dev/time#pkg-constants for more info on how the formatting
# string works. # 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" timeFormat: "2006-01-02T15:04:05.000Z07:00"
# processes is the only required field, it must have at least one process # processes is the only required field, it must have at least one process