diff options
Diffstat (limited to 'testrig')
-rw-r--r-- | testrig/config.go | 4 | ||||
-rw-r--r-- | testrig/log.go | 29 |
2 files changed, 30 insertions, 3 deletions
diff --git a/testrig/config.go b/testrig/config.go index be5efab61..3857ddb34 100644 --- a/testrig/config.go +++ b/testrig/config.go @@ -117,4 +117,8 @@ var TestDefaults = config.Values{ SMTPUsername: "", SMTPPassword: "", SMTPFrom: "GoToSocial", + + SyslogEnabled: false, + SyslogProtocol: "udp", + SyslogAddress: "localhost:514", } diff --git a/testrig/log.go b/testrig/log.go index 5db12e6e9..b0b3b9da1 100644 --- a/testrig/log.go +++ b/testrig/log.go @@ -19,14 +19,37 @@ package testrig import ( - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/log" + "gopkg.in/mcuadros/go-syslog.v2" + "gopkg.in/mcuadros/go-syslog.v2/format" ) // InitTestLog sets the global logger to trace level for logging func InitTestLog() { - err := log.Initialize(logrus.TraceLevel.String()) - if err != nil { + if err := log.Initialize(); err != nil { panic(err) } } + +// InitTestSyslog returns a test syslog running on port 42069 and a channel for reading +// messages sent to the server, or an error if something goes wrong. +// +// Callers of this function should call Kill() on the server when they're finished with it! +func InitTestSyslog() (*syslog.Server, chan format.LogParts, error) { + channel := make(syslog.LogPartsChannel) + handler := syslog.NewChannelHandler(channel) + + server := syslog.NewServer() + server.SetFormat(syslog.Automatic) + server.SetHandler(handler) + + if err := server.ListenUDP("localhost:42069"); err != nil { + return nil, nil, err + } + + if err := server.Boot(); err != nil { + return nil, nil, err + } + + return server, channel, nil +} |