1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 type writeLogger
struct {
17 func (l
*writeLogger
) Write(p
[]byte) (n
int, err error
) {
20 log
.Printf("%s %x: %v", l
.prefix
, p
[0:n
], err
)
22 log
.Printf("%s %x", l
.prefix
, p
[0:n
])
27 // NewWriteLogger returns a writer that behaves like w except
28 // that it logs (using log.Printf) each write to standard error,
29 // printing the prefix and the hexadecimal data written.
30 func NewWriteLogger(prefix
string, w io
.Writer
) io
.Writer
{
31 return &writeLogger
{prefix
, w
}
34 type readLogger
struct {
39 func (l
*readLogger
) Read(p
[]byte) (n
int, err error
) {
42 log
.Printf("%s %x: %v", l
.prefix
, p
[0:n
], err
)
44 log
.Printf("%s %x", l
.prefix
, p
[0:n
])
49 // NewReadLogger returns a reader that behaves like r except
50 // that it logs (using log.Print) each read to standard error,
51 // printing the prefix and the hexadecimal data written.
52 func NewReadLogger(prefix
string, r io
.Reader
) io
.Reader
{
53 return &readLogger
{prefix
, r
}