1
0
mirror of https://github.com/rancher/os.git synced 2025-09-19 17:38:30 +00:00

Get RancherOS logging to throw debug logs to a remote syslog server when the kernel netconsole is configured

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit
2017-08-12 03:09:47 +10:00
parent 69b54017a9
commit f793518aa6
18 changed files with 401 additions and 217 deletions

View File

@@ -1,11 +1,17 @@
package log
import (
"fmt"
"io"
"log/syslog"
"os"
"path/filepath"
"strings"
"github.com/Sirupsen/logrus"
lsyslog "github.com/Sirupsen/logrus/hooks/syslog"
"github.com/rancher/os/config/cmdline"
)
var userHook *ShowuserlogHook
@@ -118,6 +124,7 @@ func InitLogger() {
if logTheseApps() {
innerInit(false)
FsReady()
AddRSyslogHook()
pwd, err := os.Getwd()
if err != nil {
@@ -171,6 +178,37 @@ func innerInit(deferedHook bool) {
}
}
// AddRSyslogHook only needs to be called separately when using the InitDeferedLogger
// init.Main can't read /proc/cmdline at start.
// and then fails due to the network not being up
// TODO: create a "defered SyslogHook that always gets initialised, but if it fails to connect, stores the logs
// and retries connecting every time its triggered....
func AddRSyslogHook() {
val := cmdline.GetCmdline("netconsole")
netconsole := val.(string)
if netconsole != "" {
// "loglevel=8 netconsole=9999@10.0.2.14/,514@192.168.33.148/"
// 192.168.33.148:514
n := strings.Split(netconsole, ",")
if len(n) == 2 {
d := strings.Split(n[1], "@")
if len(d) == 2 {
netconsoleDestination := fmt.Sprintf("%s:%s", strings.TrimRight(d[1], "/"), d[0])
hook, err := lsyslog.NewSyslogHook("udp", netconsoleDestination, syslog.LOG_DEBUG, "")
if err == nil {
logrus.StandardLogger().Hooks.Add(hook)
Infof("Sending RancherOS Logs to: %s", netconsoleDestination)
} else {
Errorf("Error creating SyslogHook: %s", err)
}
}
}
}
}
func FsReady() {
filename := "/var/log/boot/" + filepath.Base(os.Args[0]) + ".log"
if err := os.MkdirAll(filepath.Dir(filename), os.ModeDir|0755); debugThisLogger && err != nil {