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.
This commit is contained in:
@@ -1,6 +1,18 @@
|
||||
package logging
|
||||
|
||||
// nulLWriter writes... nothing. To avoid errors, however, in downstream code it pretends it does (n will *always* == len(b)).
|
||||
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 {
|
||||
@@ -10,3 +22,37 @@ func (nw *nullWriter) Write(b []byte) (n int, err error) {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user