This repository was archived by the owner on Jan 7, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed
Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ package stackdriver
2+
3+ import (
4+ "bytes"
5+ "encoding/json"
6+ "reflect"
7+ "testing"
8+
9+ "github.com/TV4/logrus-stackdriver-formatter/test"
10+ "github.com/kr/pretty"
11+ "github.com/sirupsen/logrus"
12+ )
13+
14+ func TestStackSkip (t * testing.T ) {
15+ var out bytes.Buffer
16+
17+ logger := logrus .New ()
18+ logger .Out = & out
19+ logger .Formatter = NewFormatter (
20+ WithService ("test" ),
21+ WithVersion ("0.1" ),
22+ WithStackSkip ("github.com/TV4/logrus-stackdriver-formatter/test" ),
23+ )
24+
25+ mylog := test.LogWrapper {
26+ Logger : logger ,
27+ }
28+
29+ mylog .Error ("my log entry" )
30+
31+ var got map [string ]interface {}
32+ json .Unmarshal (out .Bytes (), & got )
33+
34+ want := map [string ]interface {}{
35+ "severity" : "ERROR" ,
36+ "message" : "my log entry" ,
37+ "serviceContext" : map [string ]interface {}{
38+ "service" : "test" ,
39+ "version" : "0.1" ,
40+ },
41+ "context" : map [string ]interface {}{
42+ "reportLocation" : map [string ]interface {}{
43+ "filePath" : "github.com/TV4/logrus-stackdriver-formatter/stackskip_test.go" ,
44+ "lineNumber" : 29.0 ,
45+ "functionName" : "TestStackSkip" ,
46+ },
47+ },
48+ }
49+
50+ if ! reflect .DeepEqual (got , want ) {
51+ t .Errorf ("unexpected output = %# v; want = %# v" , pretty .Formatter (got ), pretty .Formatter (want ))
52+ }
53+ }
Original file line number Diff line number Diff line change 1+ package test
2+
3+ import "github.com/sirupsen/logrus"
4+
5+ type LogWrapper struct {
6+ Logger * logrus.Logger
7+ }
8+
9+ func (l * LogWrapper ) Error (msg string ) {
10+ l .Logger .Error (msg )
11+ }
You can’t perform that action at this time.
0 commit comments