From 728c4a5e380cd2feef6f0f49422b3dd8297c71db Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 26 Apr 2022 17:55:24 +0200 Subject: [bugfix] Trim log entries to 1700 chars before they enter syslog (#493) * start implementing trimming hook * add test with very long test * test syslog w/ unix socket + long (trimmed) msg * trim long entries with trimhook * trim to 1700 chars instead --- testrig/log.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'testrig/log.go') diff --git a/testrig/log.go b/testrig/log.go index 5e60cad56..68d548260 100644 --- a/testrig/log.go +++ b/testrig/log.go @@ -53,3 +53,26 @@ func InitTestSyslog() (*syslog.Server, chan format.LogParts, error) { return server, channel, nil } + +// InitTestSyslog returns a test syslog running on a unix socket, 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 InitTestSyslogUnixgram(address string) (*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.ListenUnixgram(address); err != nil { + return nil, nil, err + } + + if err := server.Boot(); err != nil { + return nil, nil, err + } + + return server, channel, nil +} -- cgit v1.2.3