-
Notifications
You must be signed in to change notification settings - Fork 2
/
handler_syslog.go
57 lines (50 loc) · 1.02 KB
/
handler_syslog.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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.
// +build !windows
package log
import (
"log/syslog"
)
type syslogHandler struct {
w *syslog.Writer
*Handler
}
// Instantiates a new Handler which will write on syslog when level is reached.
func NewSyslogHandler(sw *syslog.Writer, level Severity) HandlerInterface {
return &syslogHandler{sw, &Handler{Level: level}}
}
func (sh *syslogHandler) Close() {
sh.w.Close()
}
func (sh *syslogHandler) Handle(r Record) {
sh.Handler.Prepare(&r)
switch r.Level {
case DEBUG:
sh.w.Debug(r.Formatted)
break
case INFO:
sh.w.Info(r.Formatted)
break
case NOTICE:
sh.w.Notice(r.Formatted)
break
case WARNING:
sh.w.Warning(r.Formatted)
break
case ERROR:
sh.w.Err(r.Formatted)
break
case CRITICAL:
sh.w.Crit(r.Formatted)
break
case ALERT:
sh.w.Alert(r.Formatted)
break
case EMERGENCY:
sh.w.Emerg(r.Formatted)
break
default:
panic("Unreachable")
}
}