Skip to content

Commit 5efb2f3

Browse files
committed
Add option to trim messages
1 parent dbaddd4 commit 5efb2f3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Formatter struct {
1717
NoColors bool // to disable all colors
1818
NoFieldsColors bool // to disable colors only on fields and keep levels colored
1919
ShowFullLevel bool // to show full level (e.g. [WARNING] instead of [WARN])
20+
TrimMessages bool // to trim whitespace on messages
2021
}
2122
```
2223

formatter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Formatter struct {
1818
NoColors bool // disable colors
1919
NoFieldsColors bool // color only level, default is level + fields
2020
ShowFullLevel bool // true to show full level [WARNING] instead [WARN]
21+
TrimMessages bool // true to trim whitespace on messages
2122
}
2223

2324
// Format an log entry
@@ -66,7 +67,11 @@ func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error) {
6667
}
6768

6869
// write message
69-
b.WriteString(entry.Message)
70+
if f.TrimMessages {
71+
b.WriteString(strings.TrimSpace(entry.Message))
72+
} else {
73+
b.WriteString(entry.Message)
74+
}
7075
b.WriteByte('\n')
7176

7277
return b.Bytes(), nil

0 commit comments

Comments
 (0)