go/log/handler.go

46 lines
634 B
Go
Raw Normal View History

2014-01-03 10:26:29 +04:00
package log
import (
"io"
)
type Handler interface {
Write(p []byte) (n int, err error)
2014-04-06 18:09:23 +04:00
Close() error
2014-01-03 10:26:29 +04:00
}
type StreamHandler struct {
w io.Writer
}
2014-04-06 18:09:23 +04:00
func NewStreamHandler(w io.Writer) (*StreamHandler, error) {
2014-01-03 10:26:29 +04:00
h := new(StreamHandler)
h.w = w
return h, nil
}
2014-04-06 18:09:23 +04:00
func (h *StreamHandler) Write(b []byte) (n int, err error) {
return h.w.Write(b)
2014-01-03 10:26:29 +04:00
}
2014-04-06 18:09:23 +04:00
func (h *StreamHandler) Close() error {
return nil
2014-01-03 10:26:29 +04:00
}
type NullHandler struct {
}
func NewNullHandler() (*NullHandler, error) {
return new(NullHandler), nil
}
func (h *NullHandler) Write(b []byte) (n int, err error) {
return len(b), nil
}
func (h *NullHandler) Close() {
}