7 "github.com/mjl-/mox/mlog"
10type TraceWriter struct {
17// NewTraceWriter wraps "w" into a writer that logs all writes to "log" with
18// log level trace, prefixed with "prefix".
19func NewTraceWriter(log mlog.Log, prefix string, w io.Writer) *TraceWriter {
20 return &TraceWriter{log, prefix, w, mlog.LevelTrace}
23// Write logs a trace line for writing buf to the client, then writes to the
25func (w *TraceWriter) Write(buf []byte) (int, error) {
26 w.log.Trace(w.level, w.prefix, buf)
30func (w *TraceWriter) SetTrace(level slog.Level) {
34type TraceReader struct {
41// NewTraceReader wraps reader "r" into a reader that logs all reads to "log"
42// with log level trace, prefixed with "prefix".
43func NewTraceReader(log mlog.Log, prefix string, r io.Reader) *TraceReader {
44 return &TraceReader{log, prefix, r, mlog.LevelTrace}
47// Read does a single Read on its underlying reader, logs data of successful
48// reads, and returns the data read.
49func (r *TraceReader) Read(buf []byte) (int, error) {
50 n, err := r.r.Read(buf)
52 r.log.Trace(r.level, r.prefix, buf[:n])
57func (r *TraceReader) SetTrace(level slog.Level) {