mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 01:33:10 -06:00
Syslog integration, part 1
This commit is contained in:
parent
ed4097825b
commit
3f27aceeaf
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log/syslog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -30,6 +31,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dugong"
|
"github.com/matrix-org/dugong"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type utcFormatter struct {
|
type utcFormatter struct {
|
||||||
|
|
@ -128,6 +130,9 @@ func SetupHookLogging(hooks []config.LogrusHook, componentName string) {
|
||||||
case "file":
|
case "file":
|
||||||
checkFileHookParams(hook.Params)
|
checkFileHookParams(hook.Params)
|
||||||
setupFileHook(hook, level, componentName)
|
setupFileHook(hook, level, componentName)
|
||||||
|
case "syslog":
|
||||||
|
checkSyslogHookParams(hook.Params)
|
||||||
|
setupSyslogHook(hook, level, componentName)
|
||||||
default:
|
default:
|
||||||
logrus.Fatalf("Unrecognised logging hook type: %s", hook.Type)
|
logrus.Fatalf("Unrecognised logging hook type: %s", hook.Type)
|
||||||
}
|
}
|
||||||
|
|
@ -173,6 +178,24 @@ func setupFileHook(hook config.LogrusHook, level logrus.Level, componentName str
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkSyslogHookParams(params map[string]interface{}) {
|
||||||
|
addr, ok := params["address"]
|
||||||
|
if !ok {
|
||||||
|
logrus.Fatalf("Expecting a parameter \"address\" for logging hook of type \"syslog\"")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := addr.(string); !ok {
|
||||||
|
logrus.Fatalf("Parameter \"address\" for logging hook of type \"syslog\" should be a string")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupSyslogHook(hook config.LogrusHook, level logrus.Level, componentName string) {
|
||||||
|
syslogHook, err := lSyslog.NewSyslogHook("udp", hook.Params["address"].(string), syslog.LOG_INFO, "")
|
||||||
|
if err == nil {
|
||||||
|
logrus.AddHook(syslogHook)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//CloseAndLogIfError Closes io.Closer and logs the error if any
|
//CloseAndLogIfError Closes io.Closer and logs the error if any
|
||||||
func CloseAndLogIfError(ctx context.Context, closer io.Closer, message string) {
|
func CloseAndLogIfError(ctx context.Context, closer io.Closer, message string) {
|
||||||
if closer == nil {
|
if closer == nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue