-
Notifications
You must be signed in to change notification settings - Fork 1
/
rsyslog-srv.go
63 lines (54 loc) · 1.78 KB
/
rsyslog-srv.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
58
59
60
61
62
63
package opnborg
import (
"os"
"path/filepath"
"github.com/cnaude/go-syslog/syslog/v3"
"github.com/natefinch/lumberjack"
"github.com/sirupsen/logrus"
)
// httpd spinup the internal rsyslog server
func startRSysLog(config *OPNCall) {
// create store structure
logStore := filepath.Join(config.Path, "Logs")
if err := os.MkdirAll(logStore, 0770); err != nil {
displayChan <- []byte("[RSYSLOG][ERROR][FAIL:UNABLE-TO-CREATE-FILE-STORAGE] " + logStore + ":" + err.Error())
return
}
// setup log storage
logFile := filepath.Join(logStore, "current.log")
log := logrus.New()
log.SetFormatter(&logrus.TextFormatter{})
log.SetReportCaller(false)
log.SetOutput(&lumberjack.Logger{
Filename: logFile,
MaxSize: 256, // max log file size in MB
MaxBackups: 256, // max number of old log files to keep (results in max 64GB uncompressed log storage)
MaxAge: 180, // max age in days to keep a log file
Compress: true, // Compress old log files
})
// setup log server
channel := make(syslog.LogPartsChannel)
handler := syslog.NewChannelHandler(channel)
server := syslog.NewServer()
server.SetFormat(syslog.RFC5424)
server.SetHandler(handler)
err := server.ListenUDP(config.RSysLog.Server)
if err != nil {
displayChan <- []byte("[RSYSLOG][SPIN-UP-LOG-SERVER][FAIL] listen interface (udp): " + err.Error())
}
err = server.Boot()
if err != nil {
displayChan <- []byte("[RSYSLOG][SPIN-UP-LOG-SERVER][FAIL] server " + err.Error())
}
go func(channel syslog.LogPartsChannel) {
for line := range channel {
log.Info(line)
}
}(channel)
// info
if config.Debug {
displayChan <- []byte("[RSYSLOG][SPIN-UP-LOG-SERVER] listen interface (udp): " + config.RSysLog.Server)
displayChan <- []byte("[RSYSLOG][SPIN-UP-LOG-SERVER] logging to: " + logFile)
}
server.Wait()
}