forked from TV4/logrus-stackdriver-formatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
29 lines (23 loc) · 935 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package stackdriver_test
import (
"os"
"strconv"
stackdriver "github.com/TV4/logrus-stackdriver-formatter"
"github.com/sirupsen/logrus"
)
func ExampleLogError() {
logger := logrus.New()
logger.Out = os.Stdout
logger.Formatter = stackdriver.NewFormatter(
stackdriver.WithService("test-service"),
stackdriver.WithVersion("v0.1.0"),
)
logger.Info("application up and running")
_, err := strconv.ParseInt("text", 10, 64)
if err != nil {
logger.WithError(err).Errorln("unable to parse integer")
}
// Output:
// {"message":"application up and running","severity":"INFO","context":{}}
// {"serviceContext":{"service":"test-service","version":"v0.1.0"},"message":"unable to parse integer: strconv.ParseInt: parsing \"text\": invalid syntax","severity":"ERROR","context":{"reportLocation":{"filePath":"github.com/TV4/logrus-stackdriver-formatter/example_test.go","lineNumber":23,"functionName":"ExampleLogError"}}}
}