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.
13 type writeLogger
struct {
18 func (l
*writeLogger
) Write(p
[]byte) (n
int, err os
.Error
) {
21 log
.Printf("%s %x: %v", l
.prefix
, p
[0:n
], err
)
23 log
.Printf("%s %x", l
.prefix
, p
[0:n
])
28 // NewWriteLogger returns a writer that behaves like w except
29 // that it logs (using log.Printf) each write to standard error,
30 // printing the prefix and the hexadecimal data written.
31 func NewWriteLogger(prefix
string, w io
.Writer
) io
.Writer
{
32 return &writeLogger
{prefix
, w
}
35 type readLogger
struct {
40 func (l
*readLogger
) Read(p
[]byte) (n
int, err os
.Error
) {
43 log
.Printf("%s %x: %v", l
.prefix
, p
[0:n
], err
)
45 log
.Printf("%s %x", l
.prefix
, p
[0:n
])
50 // NewReadLogger returns a reader that behaves like r except
51 // that it logs (using log.Print) each read to standard error,
52 // printing the prefix and the hexadecimal data written.
53 func NewReadLogger(prefix
string, r io
.Reader
) io
.Reader
{
54 return &readLogger
{prefix
, r
}