summaryrefslogtreecommitdiff
path: root/testrig/log.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-12-12 18:00:20 +0100
committerLibravatar GitHub <noreply@github.com>2021-12-12 18:00:20 +0100
commitc111b239f7d102ac24a79fbef420af46dfec66f9 (patch)
tree813f5c4501a6e5048fb2922e099ce92d35b33b14 /testrig/log.go
parentadd systemd service example to packaging (#342) (diff)
downloadgotosocial-c111b239f7d102ac24a79fbef420af46dfec66f9.tar.xz
Add optional syslog logrus hook (#343)
* add optional syslog logrus hook * document syslog
Diffstat (limited to 'testrig/log.go')
-rw-r--r--testrig/log.go29
1 files changed, 26 insertions, 3 deletions
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
+}