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 }