Standard library / testing/iotest

testing/iotest.NewReadLogger()

Log read bytes in hexadecimal to the standard logger. Do not wrap sensitive production streams. Expected stdout: '2 true\n'.

Formal Syntax & Structure

go syntaxgo
func NewReadLogger(prefix string, r io.Reader) io.Reader

Parameters & Attributes

NameTypeDescription
prefixstringText prepended to diagnostic logs.
rio.ReaderUnderlying reader.

Return Value

io.Reader

Result of the operation described above.

Working Example

Example Snippetgo
package main
import (  "fmt"  "log"  "strings"  "testing/iotest")
func main() {  log.SetFlags(0)  r := iotest.NewReadLogger("read", strings.NewReader("ab"))  b := make([]byte, 2)  n, err := r.Read(b)  fmt.Println(n, err == nil)}
Go Reference