go_goutils/logging/funcs_nullwriter.go
brent saner d9bd928edb
v1.9.0
ADD:
* `iox` subpackage

FIX:
* `logging` now has a way to return logWritier directly
* added significant `io.*` interface compat to logWriter -- allowing a `logging.Logger` to essentially be used for a large amount of io interaction in other libraries.
2025-07-31 03:45:32 -04:00

59 lines
1.3 KiB
Go

package logging
import (
"unicode/utf8"
)
// Close conforms a nullWriter to an io.WriteCloser. It obviously does nothing, and will always return with err == nil.
func (nw *nullWriter) Close() (err error) {
// NO-OP
return
}
// Write conforms a nullWriter to an io.Writer, but it writes... nothing. To avoid errors, however, in downstream code it pretends it does (n will *always* == len(b)).
func (nw *nullWriter) Write(b []byte) (n int, err error) {
if b == nil {
return
}
n = len(b)
return
}
// WriteByte conforms to an io.ByteWriter but again... nothing is actually written anywhere.
func (nw *nullWriter) WriteByte(c byte) (err error) {
// NO-OP
_ = c
return
}
/*
WriteRune conforms to the other Loggers. It WILL return the proper value for n (matching (bytes.Buffer).WriteRune() and (bufio.Writer).WriteRune() signatures,
and it WILL return an ErrInvalidRune if r is not a valid rune, but otherwise it will no-op.
*/
func (nw *nullWriter) WriteRune(r rune) (n int, err error) {
n = utf8.RuneLen(r)
if n < 0 {
err = ErrInvalidRune
n = 0
return
}
return
}
// WriteString conforms to an io.StringWriter but nothing is actually written. (n will *always* == len(s))
func (nw *nullWriter) WriteString(s string) (n int, err error) {
n = len(s)
return
}