--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/logging/formatter.go Sat Jul 27 10:07:00 2019 -0500
@@ -0,0 +1,76 @@
+// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com> +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + "github.com/mgutz/ansi" + log "github.com/sirupsen/logrus" +func NewFormatter(color bool) log.Formatter { + fmt := &log.TextFormatter{ + switch os.Getenv("TERM") { + fmt.DisableColors = true + fmt.DisableColors = true +func (f *Formatter) Format(entry *log.Entry) ([]byte, error) { + id, found := entry.Data["id"] + delete(entry.Data, "id") + idColor, found := entry.Data["idColor"] + delete(entry.Data, "idColor") + if id != nil && idColor != nil { + if f.fmt.DisableColors { + prefix = id.(string) + " " + prefix = idColor.(string) + id.(string) + ansi.Reset + entry.Message = prefix + " " + entry.Message + bytes, err := f.fmt.Format(entry) --- a/logging/logging.go Wed May 22 00:36:58 2019 -0500
+++ b/logging/logging.go Sat Jul 27 10:07:00 2019 -0500
@@ -23,11 +23,6 @@
log "github.com/sirupsen/logrus"
- logTemplate = `{{.Timestamp.Format "2006-01-02 15:04:05.000"}} {{index .Attrs "id"}}: {{.Message}}`
- logColorTemplate = `{{.Timestamp.Format "2006-01-02 15:04:05.000"}} {{index .Attrs "idColor"}}{{index .Attrs "id"}}{{reset}}: {{color}}{{.Message}}{{reset}}`
// Setup sets up the logging system based on the input parameters
func Setup(color, verbose bool) {
@@ -38,22 +33,7 @@
log.SetLevel(log.InfoLevel)
- fmt := &log.TextFormatter{
- switch os.Getenv("TERM") {
- fmt.DisableColors = true
- fmt.DisableColors = true
+ log.SetFormatter(NewFormatter(color))