summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/x-cray/logrus-prefixed-formatter
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-02-21 00:20:25 +0100
committerWim <wim@42.be>2018-02-21 00:20:25 +0100
commitd1227b5fc9de9f7a04fbf71292dd224aa8806411 (patch)
tree58d632c586fc3fc13783950f11265552f0f11dd5 /vendor/github.com/x-cray/logrus-prefixed-formatter
parent6ea368c383ccc19678623c51d8e4ecbbdb0a64ac (diff)
downloadmatterbridge-msglm-d1227b5fc9de9f7a04fbf71292dd224aa8806411.tar.gz
matterbridge-msglm-d1227b5fc9de9f7a04fbf71292dd224aa8806411.tar.bz2
matterbridge-msglm-d1227b5fc9de9f7a04fbf71292dd224aa8806411.zip
Use prefixed-formatter for better logging
Diffstat (limited to 'vendor/github.com/x-cray/logrus-prefixed-formatter')
-rw-r--r--vendor/github.com/x-cray/logrus-prefixed-formatter/formatter.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/vendor/github.com/x-cray/logrus-prefixed-formatter/formatter.go b/vendor/github.com/x-cray/logrus-prefixed-formatter/formatter.go
index 1235bcc3..7cb807da 100644
--- a/vendor/github.com/x-cray/logrus-prefixed-formatter/formatter.go
+++ b/vendor/github.com/x-cray/logrus-prefixed-formatter/formatter.go
@@ -11,8 +11,8 @@ import (
"sync"
"time"
- "github.com/sirupsen/logrus"
"github.com/mgutz/ansi"
+ "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh/terminal"
)
@@ -110,6 +110,11 @@ type TextFormatter struct {
// Its default value is zero, which means no padding will be applied for msg.
SpacePadding int
+ // Pad prefix field with spaces on the right for display.
+ // The value for this parameter will be the size of padding.
+ // Its default value is zero, which means no padding will be applied for prefix.
+ PrefixPadding int
+
// Color scheme to use.
colorScheme *compiledColorScheme
@@ -253,14 +258,25 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *logrus.Entry, keys
prefix := ""
message := entry.Message
+ adjustedPrefixPadding := f.PrefixPadding //compensate for ANSI color sequences
+
if prefixValue, ok := entry.Data["prefix"]; ok {
+ rawPrefixLength := len(prefixValue.(string))
prefix = colorScheme.PrefixColor(" " + prefixValue.(string) + ":")
+ adjustedPrefixPadding = f.PrefixPadding + (len(prefix) - rawPrefixLength - 1)
} else {
prefixValue, trimmedMsg := extractPrefix(entry.Message)
+ rawPrefixLength := len(prefixValue)
if len(prefixValue) > 0 {
prefix = colorScheme.PrefixColor(" " + prefixValue + ":")
message = trimmedMsg
}
+ adjustedPrefixPadding = f.PrefixPadding + (len(prefix) - rawPrefixLength - 1)
+ }
+
+ prefixFormat := "%s"
+ if f.PrefixPadding != 0 {
+ prefixFormat = fmt.Sprintf("%%-%ds", adjustedPrefixPadding)
}
messageFormat := "%s"
@@ -269,7 +285,7 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *logrus.Entry, keys
}
if f.DisableTimestamp {
- fmt.Fprintf(b, "%s%s "+messageFormat, level, prefix, message)
+ fmt.Fprintf(b, "%s"+prefixFormat+" "+messageFormat, level, prefix, message)
} else {
var timestamp string
if !f.FullTimestamp {
@@ -277,7 +293,7 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *logrus.Entry, keys
} else {
timestamp = fmt.Sprintf("[%s]", entry.Time.Format(timestampFormat))
}
- fmt.Fprintf(b, "%s %s%s "+messageFormat, colorScheme.TimestampColor(timestamp), level, prefix, message)
+ fmt.Fprintf(b, "%s %s"+prefixFormat+" "+messageFormat, colorScheme.TimestampColor(timestamp), level, prefix, message)
}
for _, k := range keys {
if k != "prefix" {