summaryrefslogtreecommitdiff
path: root/vendor/gopkg.in/mcuadros/go-syslog.v2/format/rfc6587.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 /vendor/gopkg.in/mcuadros/go-syslog.v2/format/rfc6587.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 'vendor/gopkg.in/mcuadros/go-syslog.v2/format/rfc6587.go')
-rw-r--r--vendor/gopkg.in/mcuadros/go-syslog.v2/format/rfc6587.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/gopkg.in/mcuadros/go-syslog.v2/format/rfc6587.go b/vendor/gopkg.in/mcuadros/go-syslog.v2/format/rfc6587.go
new file mode 100644
index 000000000..e0eef9174
--- /dev/null
+++ b/vendor/gopkg.in/mcuadros/go-syslog.v2/format/rfc6587.go
@@ -0,0 +1,45 @@
+package format
+
+import (
+ "bufio"
+ "bytes"
+ "strconv"
+
+ "gopkg.in/mcuadros/go-syslog.v2/internal/syslogparser/rfc5424"
+)
+
+type RFC6587 struct{}
+
+func (f *RFC6587) GetParser(line []byte) LogParser {
+ return &parserWrapper{rfc5424.NewParser(line)}
+}
+
+func (f *RFC6587) GetSplitFunc() bufio.SplitFunc {
+ return rfc6587ScannerSplit
+}
+
+func rfc6587ScannerSplit(data []byte, atEOF bool) (advance int, token []byte, err error) {
+ if atEOF && len(data) == 0 {
+ return 0, nil, nil
+ }
+
+ if i := bytes.IndexByte(data, ' '); i > 0 {
+ pLength := data[0:i]
+ length, err := strconv.Atoi(string(pLength))
+ if err != nil {
+ if string(data[0:1]) == "<" {
+ // Assume this frame uses non-transparent-framing
+ return len(data), data, nil
+ }
+ return 0, nil, err
+ }
+ end := length + i + 1
+ if len(data) >= end {
+ // Return the frame with the length removed
+ return end, data[i+1 : end], nil
+ }
+ }
+
+ // Request more data
+ return 0, nil, nil
+}