2017-08-09 08:45:45 +02:00
|
|
|
package syslog
|
|
|
|
|
2017-08-10 20:11:35 +02:00
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"strconv"
|
2017-08-09 08:45:45 +02:00
|
|
|
|
2017-08-10 20:11:35 +02:00
|
|
|
"github.com/genofire/logmania/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
var SyslogPriorityMap = map[int]log.LogLevel{
|
2017-08-09 08:45:45 +02:00
|
|
|
0: log.PanicLevel,
|
|
|
|
1: log.PanicLevel,
|
|
|
|
2: log.PanicLevel,
|
|
|
|
3: log.ErrorLevel,
|
|
|
|
4: log.WarnLevel,
|
|
|
|
5: log.InfoLevel,
|
|
|
|
6: log.InfoLevel,
|
|
|
|
7: log.DebugLevel,
|
|
|
|
}
|
|
|
|
|
2017-08-10 20:11:35 +02:00
|
|
|
func toLogEntry(msg []byte, from string) *log.Entry {
|
|
|
|
re := regexp.MustCompile("<([0-9]*)>(.*)")
|
|
|
|
match := re.FindStringSubmatch(string(msg))
|
2017-08-09 08:45:45 +02:00
|
|
|
|
2017-08-10 20:11:35 +02:00
|
|
|
if len(match) <= 1 {
|
2017-08-09 08:45:45 +02:00
|
|
|
return &log.Entry{
|
2017-08-10 20:11:35 +02:00
|
|
|
Level: log.DebugLevel,
|
|
|
|
Text: string(msg),
|
|
|
|
Hostname: from,
|
2017-08-09 08:45:45 +02:00
|
|
|
}
|
|
|
|
}
|
2017-08-10 20:11:35 +02:00
|
|
|
v, _ := strconv.Atoi(match[1])
|
|
|
|
prio := v % 8
|
|
|
|
text := match[2]
|
2017-08-09 08:45:45 +02:00
|
|
|
|
|
|
|
return &log.Entry{
|
2017-08-10 20:11:35 +02:00
|
|
|
Level: SyslogPriorityMap[prio],
|
|
|
|
Text: text,
|
|
|
|
Hostname: from,
|
2017-08-09 08:45:45 +02:00
|
|
|
}
|
|
|
|
}
|