forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syslog.go
34 lines (30 loc) · 809 Bytes
/
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
//go:build !windows
// +build !windows
package uadmin
import (
"log/syslog"
)
var syslogMap = map[int]syslog.Priority{
DEBUG: syslog.LOG_DEBUG,
WORKING: syslog.LOG_DEBUG,
INFO: syslog.LOG_INFO,
OK: syslog.LOG_INFO,
WARNING: syslog.LOG_WARNING,
ERROR: syslog.LOG_ERR,
CRITICAL: syslog.LOG_CRIT,
ALERT: syslog.LOG_ALERT,
EMERGENCY: syslog.LOG_EMERG,
}
// Syslogf records a log in the system in syslog. For Windows it created
// a file and records the logs there.
func Syslogf(level int, msg string, a ...interface{}) {
logger, err := syslog.NewLogger(syslog.LOG_LOCAL0|syslogMap[level], 0)
if err != nil {
// Trail(ERROR, "Handler.NewLogger. %s", err.Error())
return
}
if len(msg) != 0 && msg[len(msg)-1] != '\n' {
msg += "\n"
}
logger.Printf(msg, a...)
}