summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadim Hatlapatka <hata.radim@gmail.com>2022-07-05 03:28:34 +0200
committerGitHub <noreply@github.com>2022-07-04 21:28:34 -0400
commit8771236337c6b010b26a4b5e096278b4ac2a7b98 (patch)
tree79bf49a292a555ab0ab1ed2765939f3ffc1fcf1e
parente6304eec19319659eec61bdcbd51d33966b46f06 (diff)
Include additional field names to finder for compact printer (#4)
* Include additional field names to finder for compact printer * Adding traceId to the fields & prolonging logger part as in Java the names of loggers are rather longer * Remove changes to formatting for existing fields
-rw-r--r--compact_printer.go8
-rw-r--r--compact_printer_test.go12
2 files changed, 12 insertions, 8 deletions
diff --git a/compact_printer.go b/compact_printer.go
index 9c47103..5bd0fd8 100644
--- a/compact_printer.go
+++ b/compact_printer.go
@@ -37,18 +37,22 @@ type FieldFmt struct {
// for most types of logs.
var DefaultCompactPrinterFieldFmt = []FieldFmt{{
Name: "level",
- Finders: []FieldFinder{ByNames("level", "severity")},
+ Finders: []FieldFinder{ByNames("level", "severity", "logLevel")},
Transformers: []Transformer{Truncate(4), UpperCase, ColorMap(LevelColors)},
}, {
Name: "time",
- Finders: []FieldFinder{ByNames("timestamp", "time")},
+ Finders: []FieldFinder{ByNames("timestamp", "time", "ts")},
}, {
Name: "thread",
Transformers: []Transformer{Ellipsize(16), Format("[%s]"), RightPad(18), ColorSequence(AllColors)},
}, {
Name: "logger",
+ Finders: []FieldFinder{ByNames("logger", "caller")},
Transformers: []Transformer{Ellipsize(20), Format("%s|"), LeftPad(21), ColorSequence(AllColors)},
}, {
+ Name: "traceId",
+ Transformers: []Transformer{Format("%s|"), ColorSequence(AllColors)},
+}, {
Name: "message",
Finders: []FieldFinder{ByNames("message", "msg", "textPayload", "jsonPayload.message")},
}, {
diff --git a/compact_printer_test.go b/compact_printer_test.go
index 9f3465a..42b9326 100644
--- a/compact_printer_test.go
+++ b/compact_printer_test.go
@@ -27,16 +27,16 @@ func TestCompactPrinter_Print(t *testing.T) {
formatted string
}{{
name: "basic",
- json: `{"timestamp":"2019-01-01 15:23:45","level":"INFO","thread":"truck-manager","logger":"TruckRepairServiceOverlordManager","message":"There are 7 more trucks in the garage to fix. Get to work."}`,
- formatted: "INFO 2019-01-01 15:23:45 [truck-manager] TruckRepa…ordManager| There are 7 more trucks in the garage to fix. Get to work.\n",
+ json: `{"timestamp":"2019-01-01 15:23:45","level":"INFO","thread":"truck-manager","traceId":"123125f435d657a1","logger":"TruckRepairServiceOverlordManager","message":"There are 7 more trucks in the garage to fix. Get to work."}`,
+ formatted: "INFO 2019-01-01 15:23:45 [truck-manager] TruckRepa…ordManager| 123125f435d657a1| There are 7 more trucks in the garage to fix. Get to work.\n",
}, {
name: "exception",
- json: `{"timestamp":"2019-01-01 15:34:45","level":"ERROR","thread":"repair-worker-2","logger":"TruckRepairMinion","message":"Truck 5 has is really broken! I'm need parts, waiting till they come."}`,
- formatted: `ERRO 2019-01-01 15:34:45 [repair-worker-2] TruckRepairMinion| Truck 5 has is really broken! I'm need parts, waiting till they come.
+ json: `{"timestamp":"2019-01-01 15:34:45","level":"ERROR","thread":"repair-worker-2","traceId":"123125f435d657a1","logger":"TruckRepairMinion","message":"Truck 5 has is really broken! I'm need parts, waiting till they come."}`,
+ formatted: `ERRO 2019-01-01 15:34:45 [repair-worker-2] TruckRepairMinion| 123125f435d657a1| Truck 5 has is really broken! I'm need parts, waiting till they come.
`}, {
name: "logrus_pgk_error",
- json: `{"timestamp":"2019-01-01 15:23:45","level":"error","message":"an error occurred","error":"BOOM!","stack":"github.com/pkg/errors_test.fn\n\t/home/dfc/src/github.com/pkg/errors/example_test.go:47\ngithub.com/pkg/errors_test.Example_stackTrace\n\t/home/dfc/src/github.com/pkg/errors/example_test.go:127\n"}`,
- formatted: `ERRO 2019-01-01 15:23:45 an error occurred
+ json: `{"timestamp":"2019-01-01 15:23:45","level":"error","message":"an error occurred","traceId":"123125f435d657a1","error":"BOOM!","stack":"github.com/pkg/errors_test.fn\n\t/home/dfc/src/github.com/pkg/errors/example_test.go:47\ngithub.com/pkg/errors_test.Example_stackTrace\n\t/home/dfc/src/github.com/pkg/errors/example_test.go:127\n"}`,
+ formatted: `ERRO 2019-01-01 15:23:45 123125f435d657a1| an error occurred
BOOM!
github.com/pkg/errors_test.fn
/home/dfc/src/github.com/pkg/errors/example_test.go:47