Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log: Logger does not return errors from underlying writer #21127

Closed
AndyNortrup opened this issue Jul 22, 2017 · 1 comment
Closed

log: Logger does not return errors from underlying writer #21127

AndyNortrup opened this issue Jul 22, 2017 · 1 comment

Comments

@AndyNortrup
Copy link

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.1 darwin/amd64

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

GOARCH="amd64" GOBIN="/Users/andy/work/bin" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/andy/work" GORACE="" GOROOT="/usr/local/Cellar/go/1.8.1/libexec" GOTOOLDIR="/usr/local/Cellar/go/1.8.1/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" CC="clang" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/mr/6sjcksy91jj40ksm0h_6fzhm0000gn/T/go-build558308436=/tmp/go-build -gno-record-gcc-switches -fno-common" CXX="clang++" CGO_ENABLED="1" PKG_CONFIG="pkg-config" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2"

What did you do?

The struct log.Logger methods Print, Printf do not return errors from underlying writer to the caller. The Output method returns the error but Print and Printf have no return arguments.

In my case I'm writing an io.Writer that sends data to a Splunk HTTP Event Collector so that I can use it with log.Logger to do logging inside of an application. Because of the use of a network and authorization an entry could be rejected or error, but the caller of log.Printf("info") would never know that their log data was lost.

What did you expect to see?

log.Printf and log.Print return errors from log.Output

What did you see instead?

log.Printf and log.Print return no errors to the caller.

@bradfitz
Copy link
Contributor

It is intentional that log.Logger.Print methods don't return errors.

In addition to the ugliness of all logging call sites checking for errors, what would you do if it returned an error? Log?

If you want to encode the policy for what to do on log failures, do so in your Logger.SetOutput io.Writer and log to stdout or panic or buffer to memory or log elsewhere, etc.

Even if we wanted to change the behavior here, https://golang.org/doc/go1compat precludes doing so.

@mikioh mikioh changed the title log.Logger does not return errors from underlying writer log: Logger does not return errors from underlying writer Aug 2, 2017
@golang golang locked and limited conversation to collaborators Aug 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants