Skip to content

log/slog: JSONHandler does not format the source attribute in conformance with its documentation #60329

@komuw

Description

@komuw

What version of Go are you using (go version)?

$ go version
go version go1.20.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

gotip version
  go version devel go1.21-b950cc8f11 Sat May 20 21:53:52 2023 +0000 linux/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/komuw/.cache/go-build'
GOENV='/home/komuw/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/komuw/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/komuw/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/komuw/sdk/gotip'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLDIR='/home/komuw/sdk/gotip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.21-b950cc8f11 Sat May 20 21:53:52 2023 +0000'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/komuw/Downloads/cool/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/run/user/1000/go-build3180755045=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Run the program; https://go.dev/play/p/YVBdftehuQ7

What did you expect to see?

{"time":"2023-05-21T17:12:19.865170422+03:00","level":"INFO","source":"/home/cool/main.go:15",,"msg":"hey"}

What did you see instead?

{"time":"2023-05-21T17:12:19.865170422+03:00","level":"INFO","source":{"function":"main.main","file":"/home/cool/main.go","line":15},"msg":"hey"}

The docs;

// If the AddSource option is set and source information is available,
// the key is "source"
// and the value is output as "FILE:LINE".
say; If the AddSource option is set and source information is available, the key is "source" and the value is output as "FILE:LINE".

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions