You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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
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 butPrint
andPrintf
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.
The text was updated successfully, but these errors were encountered: