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

Commit

Permalink
Make example part of test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Olsson committed Apr 14, 2018
1 parent 18a2437 commit 4580df3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,19 @@ Here's a sample entry (prettified) from the example:

```json
{
"context": { "reportLocation": {
"filePath": "example/main.go",
"lineNumber": 22,
"functionName": "main"
}
},
"message": "unable to parse integer: strconv.ParseInt: parsing \"text\": invalid syntax",
"serviceContext": {
"service": "test-service",
"version": "v0.1.0"
},
"severity": "ERROR"
"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": 21,
"functionName": "ExampleLogError"
}
}
}
```

Expand Down
26 changes: 0 additions & 26 deletions example/main.go

This file was deleted.

29 changes: 29 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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"}}}
}

0 comments on commit 4580df3

Please sign in to comment.