-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sdual/fix-comment
Add comment
- Loading branch information
Showing
3 changed files
with
54 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
# roachslog | ||
|
||
[![Go](https://github.com/sdual/roachslog/actions/workflows/go-test.yml/badge.svg)](https://github.com/sdual/roachslog/actions/workflows/go-test.yml) | ||
|
||
## Examples | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/cockroachdb/errors" | ||
"github.com/sdual/roachslog" | ||
) | ||
|
||
func main() { | ||
ops := slog.HandlerOptions{ | ||
AddSource: true, | ||
Level: slog.LevelInfo, | ||
} | ||
|
||
handler := slog.NewJSONHandler(os.Stdout, &ops) | ||
rsHandler := roachslog.NewReachSlogHandler(handler) | ||
slog.SetDefault(slog.New(rsHandler)) | ||
|
||
err := errors.New("error") | ||
slog.Error("error occurred", roachslog.Err(err)) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package roachslog | ||
|
||
import ( | ||
"log/slog" | ||
) | ||
|
||
const errAttrKey = "error" | ||
|
||
func Err(err error) slog.Attr { | ||
return slog.Any(errAttrKey, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters