Skip to content

Commit

Permalink
Merge pull request #3 from sdual/description-readme
Browse files Browse the repository at this point in the history
Add description to README
  • Loading branch information
sdual authored Sep 7, 2024
2 parents 33fa102 + d0ffb68 commit 5d1f7ba
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

[![Go](https://github.com/sdual/roachslog/actions/workflows/go-test.yml/badge.svg)](https://github.com/sdual/roachslog/actions/workflows/go-test.yml)

## Examples
This library allows cockroachdb/errors stacktrace to be output as a slog attribute.

## Usage

```go
package main
Expand All @@ -25,7 +27,26 @@ func main() {
rsHandler := roachslog.NewReachSlogHandler(handler)
slog.SetDefault(slog.New(rsHandler))

err := errors.New("error")
err := doSomething()
slog.Error("error occurred", roachslog.Err(err))
}

func doSomething() error {
return errors.New("error")
}
```

```json
{
"time": "2024-09-06T12:44:15.107483+09:00",
"level": "ERROR",
"source": {
"function": "main.main",
"file": "/Users/sdual/repos/golang/sample/main.go",
"line": 22
},
"msg": "error occurred",
"error": "error",
"stacktrace": "\nmain.doSomething\n\t/Users/sdual/repos/golang/sample/main.go:26\nmain.main\n\t/Users/sdual/repos/golang/sample/main.go:21\nruntime.main\n\t/Users/sdual/go/1.22.4/pkg/mod/golang.org/[email protected]/src/runtime/proc.go:272\nruntime.goexit\n\t/Users/sdual/go/1.22.4/pkg/mod/golang.org/[email protected]/src/runtime/asm_arm64.s:1223"
}
```

0 comments on commit 5d1f7ba

Please sign in to comment.