Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 4580df3

Browse files
author
Marcus Olsson
committed
Make example part of test suite
1 parent 18a2437 commit 4580df3

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,19 @@ Here's a sample entry (prettified) from the example:
4242

4343
```json
4444
{
45-
"context": { "reportLocation": {
46-
"filePath": "example/main.go",
47-
"lineNumber": 22,
48-
"functionName": "main"
49-
}
50-
},
51-
"message": "unable to parse integer: strconv.ParseInt: parsing \"text\": invalid syntax",
5245
"serviceContext": {
5346
"service": "test-service",
5447
"version": "v0.1.0"
5548
},
56-
"severity": "ERROR"
49+
"message": "unable to parse integer: strconv.ParseInt: parsing \"text\": invalid syntax",
50+
"severity": "ERROR",
51+
"context": {
52+
"reportLocation": {
53+
"filePath": "github.com/TV4/logrus-stackdriver-formatter/example_test.go",
54+
"lineNumber": 21,
55+
"functionName": "ExampleLogError"
56+
}
57+
}
5758
}
5859
```
5960

example/main.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

example_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package stackdriver_test
2+
3+
import (
4+
"os"
5+
"strconv"
6+
7+
stackdriver "github.com/TV4/logrus-stackdriver-formatter"
8+
"github.com/sirupsen/logrus"
9+
)
10+
11+
func ExampleLogError() {
12+
logger := logrus.New()
13+
logger.Out = os.Stdout
14+
logger.Formatter = stackdriver.NewFormatter(
15+
stackdriver.WithService("test-service"),
16+
stackdriver.WithVersion("v0.1.0"),
17+
)
18+
19+
logger.Info("application up and running")
20+
21+
_, err := strconv.ParseInt("text", 10, 64)
22+
if err != nil {
23+
logger.WithError(err).Errorln("unable to parse integer")
24+
}
25+
26+
// Output:
27+
// {"message":"application up and running","severity":"INFO","context":{}}
28+
// {"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"}}}
29+
}

0 commit comments

Comments
 (0)