logging/backend.go

41 lines
620 B
Go
Raw Normal View History

2013-06-21 18:35:47 +02:00
package logging
import (
"io"
"os"
)
type Backend interface {
Write(*Record) error
SetLevel(Level)
SetFormatter(*Formatter)
}
type StdoutBackend struct {
l io.Writer
level Level
formatter *Formatter
}
func NewStdoutBackend() (b *StdoutBackend) {
b = &StdoutBackend{
l: os.Stdout,
formatter: &defaultFormatter,
}
return
}
func (b StdoutBackend) Write(r *Record) error {
text := (*b.formatter)(r)
_, err := io.WriteString(b.l, text)
return err
2013-06-21 18:35:47 +02:00
}
func (b *StdoutBackend) SetLevel(l Level) {
b.level = l
}
func (b *StdoutBackend) SetFormatter(f *Formatter) {
b.formatter = f
}