2017-08-09 08:45:45 +02:00
|
|
|
package syslog
|
|
|
|
|
2017-08-10 20:11:35 +02:00
|
|
|
import (
|
2019-06-20 09:25:43 +02:00
|
|
|
"github.com/bdlm/log"
|
|
|
|
logstd "github.com/bdlm/std/logger"
|
2017-10-25 00:36:16 +02:00
|
|
|
|
2019-08-08 15:51:55 +02:00
|
|
|
libSyslog "dev.sum7.eu/sum7/logmania/lib/syslog"
|
2017-08-10 20:11:35 +02:00
|
|
|
)
|
|
|
|
|
2019-06-20 09:25:43 +02:00
|
|
|
var SyslogPriorityMap = map[int]logstd.Level{
|
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 {
|
2017-08-11 17:45:42 +02:00
|
|
|
syslogMsg := libSyslog.Parse(msg)
|
2017-08-09 08:45:45 +02:00
|
|
|
|
2017-10-25 00:36:16 +02:00
|
|
|
entry := log.NewEntry(nil)
|
|
|
|
entry = entry.WithField("hostname", from)
|
|
|
|
entry.Time = syslogMsg.Timestemp
|
|
|
|
entry.Level = SyslogPriorityMap[syslogMsg.Severity]
|
|
|
|
entry.Message = syslogMsg.Content
|
|
|
|
return entry
|
2017-08-09 08:45:45 +02:00
|
|
|
}
|