Debian Codegraph @

syslogparser.go

raw symbols SCIP
1 // Package syslogparser implements functions to parsing RFC3164 or RFC5424 syslog messages.
2 // syslogparser provides one subpackage per RFC with an example usage for which RFC.
3 package syslogparser
4
5 import (
6 "time"
7
8 "github.com/jeromer/syslogparser/parsercommon"
9 )
10
11 type RFC uint8
12
13 const (
14 RFC_UNKNOWN = iota
15 RFC_3164
16 RFC_5424
17 )
18
19 type LogParts map[string]interface{}
20
21 type LogParser interface {
22 Parse() error
23 Dump() LogParts
24 WithTimestampFormat(string)
25 WithLocation(*time.Location)
26 WithHostname(string)
27 WithTag(string)
28 }
29
30 func DetectRFC(buff []byte) (RFC, error) {
31 max := 10
32 var v int
33 var err error
34
35 for i := 0; i < max; i++ {
36 if buff[i] == '>' && i < max {
37 x := i + 1
38
39 v, err = parsercommon.ParseVersion(
40 buff, &x, max,
41 )
42
43 break
44 }
45 }
46
47 if err != nil {
48 return RFC_UNKNOWN, err
49 }
50
51 if v == parsercommon.NO_VERSION {
52 return RFC_3164, nil
53 }
54
55 return RFC_5424, nil
56 }