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.ReaderParameters & Attributes
| Name | Type | Description |
|---|---|---|
| prefix | string | Text prepended to diagnostic logs. |
| r | io.Reader | Underlying 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)}