-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
27 lines (22 loc) · 1008 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package rfc5424_test
import (
"bytes"
"fmt"
"github.com/tonimelisma/rfc5424"
)
func ExampleParseMultiple() {
testMessageBuffer := []byte(`83 <40>1 2012-11-30T06:45:29+00:00 host app web.3 - State changed from starting to up
119 <40>1 2012-11-30T06:45:26+00:00 host app web.3 - Starting process with command 'bundle exec rackup config.ru -p 24405'
`)
testMessageReader := bytes.NewReader(testMessageBuffer)
messageArray, err := rfc5424.ParseMultiple(testMessageReader)
if err != nil {
fmt.Println("error parsing syslog messages:", err.Error())
}
for _, message := range messageArray {
fmt.Printf("%v [%v.%v] %v %v %v: %v\n", message.Timestamp, message.Facility, message.Severity, message.Hostname, message.AppName, message.ProcID, message.Message)
}
// Output:
// 2012-11-30T06:45:29+00:00 [syslog.emerg] host app web.3: State changed from starting to up
// 2012-11-30T06:45:26+00:00 [syslog.emerg] host app web.3: Starting process with command 'bundle exec rackup config.ru -p 24405'
}