Skip to content

Implement slog.LogValuer - #129

Open
nozo-moto wants to merge 3 commits into
cockroachdb:masterfrom
nozo-moto:implment-logvalue-method-to-withstack
Open

Implement slog.LogValuer#129
nozo-moto wants to merge 3 commits into
cockroachdb:masterfrom
nozo-moto:implment-logvalue-method-to-withstack

Conversation

@nozo-moto

@nozo-motonozo-moto commented Sep 18, 2023

Copy link
Copy Markdown

#107

This change is Reviewable

code
package main
import (
"context""log/slog""os""github.com/cockroachdb/errors"
)
funcf1() error {
returnerrors.Wrap(f2(), "wrapped error 1")
}
funcf2() error {
returnerrors.Wrap(f3(), "wrapped error 2")
}
funcf3() error {
returnerrors.Wrap(f4(), "wrapped error 3")
}
funcf4() error {
returnerrors.Wrap(f5(), "wrapped error 4")
}
funcf5() error {
returnerrors.New("error root")
}
funcmain() {
ctx:=context.Background()
err:=f1()
logger:=slog.New(slog.NewJSONHandler(os.Stdout, nil))
logger.InfoContext(ctx, "test", slog.Any("error", err))
}
result
{
"time": "2023-09-18T17:57:09.438517+09:00",
"level": "INFO",
"msg": "test",
"error": {
"message": "wrapped error 1: wrapped error 2: wrapped error 3: wrapped error 4: error root",
"stacktrace": {
"main.f1": {
"file": "/Users/nozo/tmp/cockloaddb-slog-try/main.go",
"name": "main.f1",
"line": 12
},
"main.main": {
"file": "/Users/nozo/tmp/cockloaddb-slog-try/main.go",
"name": "main.main",
"line": 33
},
"runtime.main": {
"file": "/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go",
"name": "runtime.main",
"line": 267
},
"runtime.goexit": {
"file": "/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/asm_arm64.s",
"name": "runtime.goexit",
"line": 1197
}
}
}
}

@cockroach-teamcity

cockroach-teamcity commented Sep 18, 2023

Copy link
Copy Markdown
Member

CLA assistant check
All committers have signed the CLA.

@nozo-motonozo-moto changed the title implement LogValue method to WithStackImplement slog.LogValuerSep 18, 2023
@nozo-moto
nozo-motoforce-pushed the implment-logvalue-method-to-withstack branch from adf5647 to 556c210CompareSeptember 18, 2023 09:00
@nozo-moto
nozo-moto marked this pull request as ready for review September 18, 2023 09:01
@nozo-motonozo-moto mentioned this pull request Sep 22, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@nozo-moto@cockroach-teamcity