This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_syslog.go
41 lines (36 loc) · 1.56 KB
/
output_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
// +build !windows
package xlog
import (
"github.com/rs/xlog"
"io"
"log/syslog"
)
// NewSyslogOutput returns JSONOutputs in a LevelOutput with writers set to syslog
// with the proper priority added to a LOG_USER facility.
// If network and address are empty, Dial will connect to the local syslog server.
func NewSyslogOutput(network, address, tag string) xlog.Output {
return NewSyslogOutputFacility(network, address, tag, syslog.LOG_USER)
}
// NewSyslogOutputFacility returns JSONOutputs in a LevelOutput with writers set to syslog
// with the proper priority added to the passed facility.
// If network and address are empty, Dial will connect to the local syslog server.
func NewSyslogOutputFacility(network, address, tag string, facility syslog.Priority) xlog.Output {
o := LevelOutput{
Debug: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_DEBUG, tag)),
Info: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_INFO, tag)),
Warn: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_WARNING, tag)),
Error: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_ERR, tag)),
}
return o
}
// NewSyslogWriter returns a writer ready to be used with output modules.
// If network and address are empty, Dial will connect to the local syslog server.
func NewSyslogWriter(network, address string, prio syslog.Priority, tag string) io.Writer {
s, err := syslog.Dial(network, address, prio, tag)
if err != nil {
m := "syslog dial error: " + err.Error()
critialLogger.Print(m)
panic(m)
}
return s
}