-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
143 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package format | ||
|
||
import ( | ||
"bufio" | ||
|
||
"github.com/jeromer/syslogparser" | ||
) | ||
|
||
type Format interface { | ||
GetParser([]byte) syslogparser.LogParser | ||
GetSplitFunc() bufio.SplitFunc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package format | ||
|
||
import ( | ||
"testing" | ||
|
||
. "launchpad.net/gocheck" | ||
) | ||
|
||
func Test(t *testing.T) { TestingT(t) } | ||
|
||
type FormatSuite struct{} | ||
|
||
var _ = Suite(&FormatSuite{}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package format | ||
|
||
import ( | ||
"bufio" | ||
|
||
"github.com/jeromer/syslogparser" | ||
"github.com/jeromer/syslogparser/rfc3164" | ||
) | ||
|
||
type RFC3164 struct{} | ||
|
||
func (f *RFC3164) GetParser(line []byte) syslogparser.LogParser { | ||
return rfc3164.NewParser(line) | ||
} | ||
|
||
func (f *RFC3164) GetSplitFunc() bufio.SplitFunc { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package format | ||
|
||
import ( | ||
. "launchpad.net/gocheck" | ||
) | ||
|
||
func (s *FormatSuite) TestRFC3164_SingleSplit(c *C) { | ||
f := RFC3164{} | ||
c.Assert(f.GetSplitFunc(), IsNil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package format | ||
|
||
import ( | ||
"bufio" | ||
|
||
"github.com/jeromer/syslogparser" | ||
"github.com/jeromer/syslogparser/rfc5424" | ||
) | ||
|
||
type RFC5424 struct{} | ||
|
||
func (f *RFC5424) GetParser(line []byte) syslogparser.LogParser { | ||
return rfc5424.NewParser(line) | ||
} | ||
|
||
func (f *RFC5424) GetSplitFunc() bufio.SplitFunc { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package format | ||
|
||
import ( | ||
. "launchpad.net/gocheck" | ||
) | ||
|
||
func (s *FormatSuite) TestRFC5424_SingleSplit(c *C) { | ||
f := RFC5424{} | ||
c.Assert(f.GetSplitFunc(), IsNil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package format | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"strconv" | ||
|
||
"github.com/jeromer/syslogparser" | ||
"github.com/jeromer/syslogparser/rfc5424" | ||
) | ||
|
||
type RFC6587 struct{} | ||
|
||
func (f *RFC6587) GetParser(line []byte) syslogparser.LogParser { | ||
return 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 { | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters