This is a customized formatter which implements Fommatter
of logrus.
This formatter mainly focuses on desktop application logging, since we might need process ID, local time stamp, function name, and lines.
And one of the goals of this formatter is making logs human-readable.
2021-04-25T20:37:27+08:00 [TRAC] [2070] some trace message
2021-04-25T20:37:27+08:00 [DEBU] [2070] some debug message
2021-04-25T20:37:27+08:00 [INFO] [2070] some info message
2021-04-25T20:37:27+08:00 [WARN] [2070] some warning message
2021-04-25T20:37:27+08:00 [ERRO] [2070] some error message
2021-04-25T20:37:27+08:00 [FATA] [2070] some fatal message
type AppFormatter struct {
DisableTimestamp bool
DisablePID bool
}
import (
"github.com/SivWatt/formatter"
"github.com/sirupsen/logrus"
)
log := logrus.New()
log.SetFormatter(&formatter.AppFormatter{})
log.Info("some info message")
// Output: 2021-04-25T20:30:03+08:00 [INFO] [1228] some info message
log.WithField("key", "value").Debug("some debug message")
// Output: 2021-04-25T20:30:03+08:00 [DEBU] [1228] some debug message [key:value]
Feel free to let me know if there is anything needed to be improved. (via issue)