-
Notifications
You must be signed in to change notification settings - Fork 2
/
handler_writecloser.go
39 lines (31 loc) · 1020 Bytes
/
handler_writecloser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2013 Marc Weistroff. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package log
import (
"io"
"os"
)
type writeCloserHandler struct {
wc io.WriteCloser
*Handler
}
// Instantiates a new Handler which will write on wc when level is reached.
func NewWriteCloserHandler(wc io.WriteCloser, level Severity) HandlerInterface {
return &writeCloserHandler{wc, &Handler{Level: level}}
}
// Instantiates a new Handler which will write on Stdout when level is reached.
func NewStdoutHandler(level Severity) HandlerInterface {
return NewWriteCloserHandler(os.Stdout, level)
}
// Instantiates a new Handler which will write on Stderr when level is reached.
func NewStderrHandler(level Severity) HandlerInterface {
return NewWriteCloserHandler(os.Stderr, level)
}
func (wch *writeCloserHandler) Close() {
wch.wc.Close()
}
func (wch *writeCloserHandler) Handle(r Record) {
wch.Handler.Prepare(&r)
wch.wc.Write([]byte(r.Formatted))
}