@@ -3,7 +3,6 @@ package format
3
3
import (
4
4
"bufio"
5
5
"bytes"
6
- "errors"
7
6
"strconv"
8
7
9
8
"gopkg.in/mcuadros/go-syslog.v2/internal/syslogparser/rfc3164"
@@ -31,33 +30,40 @@ const (
31
30
detectedRFC6587 = iota
32
31
)
33
32
34
- func detect (data []byte ) (detected int , err error ) {
33
+ /*
34
+ * Will always fallback to rfc3164 (see section 4.3.3)
35
+ */
36
+ func detect (data []byte ) int {
35
37
// all formats have a sapce somewhere
36
38
if i := bytes .IndexByte (data , ' ' ); i > 0 {
37
39
pLength := data [0 :i ]
38
40
if _ , err := strconv .Atoi (string (pLength )); err == nil {
39
- return detectedRFC6587 , nil
41
+ return detectedRFC6587
42
+ }
43
+ // are we starting with <
44
+ if data [0 ] != '<' {
45
+ return detectedRFC3164
40
46
}
41
-
42
47
// is there a close angle bracket before the ' '? there should be
43
48
angle := bytes .IndexByte (data , '>' )
44
49
if (angle < 0 ) || (angle >= i ) {
45
- return detectedUnknown , errors . New ( "No close angle bracket before space" )
50
+ return detectedRFC3164
46
51
}
47
52
48
53
// if a single digit immediately follows the angle bracket, then a space
49
54
// it is RFC5424, as RFC3164 must begin with a letter (month name)
50
55
if (angle + 2 == i ) && (data [angle + 1 ] >= '0' ) && (data [angle + 1 ] <= '9' ) {
51
- return detectedRFC5424 , nil
56
+ return detectedRFC5424
52
57
} else {
53
- return detectedRFC3164 , nil
58
+ return detectedRFC3164
54
59
}
55
60
}
56
- return detectedUnknown , nil
61
+ // fallback to rfc 3164 section 4.3.3
62
+ return detectedRFC3164
57
63
}
58
64
59
65
func (f * Automatic ) GetParser (line []byte ) LogParser {
60
- switch format , _ := detect (line ); format {
66
+ switch format := detect (line ); format {
61
67
case detectedRFC3164 :
62
68
return & parserWrapper {rfc3164 .NewParser (line )}
63
69
case detectedRFC5424 :
@@ -82,7 +88,7 @@ func (f *Automatic) automaticScannerSplit(data []byte, atEOF bool) (advance int,
82
88
return 0 , nil , nil
83
89
}
84
90
85
- switch format , err := detect (data ); format {
91
+ switch format := detect (data ); format {
86
92
case detectedRFC6587 :
87
93
return rfc6587ScannerSplit (data , atEOF )
88
94
case detectedRFC3164 , detectedRFC5424 :
0 commit comments