Skip to content

Commit e5ef80c

Browse files
committed
docs(rfc3164): examples for WithTimezone option
Signed-off-by: Leonardo Di Donato <[email protected]>
1 parent e9f2038 commit e5ef80c

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

rfc3164/example_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package rfc3164
22

33
import (
4+
// "time"
5+
6+
"time"
7+
48
"github.com/davecgh/go-spew/spew"
59
)
610

@@ -52,6 +56,50 @@ func Example_currentyear() {
5256
// })
5357
}
5458

59+
func Example_withtimezone() {
60+
cet, _ := time.LoadLocation("CET")
61+
i := []byte(`<13>Jan 30 02:08:03 host app: Test`)
62+
p := NewParser(WithTimezone(cet))
63+
m, _ := p.Parse(i)
64+
output(m)
65+
// Output:
66+
// (*rfc3164.SyslogMessage)({
67+
// Base: (syslog.Base) {
68+
// Facility: (*uint8)(1),
69+
// Severity: (*uint8)(5),
70+
// Priority: (*uint8)(13),
71+
// Timestamp: (*time.Time)(0000-01-30 03:08:03 +0100 CET),
72+
// Hostname: (*string)((len=4) "host"),
73+
// Appname: (*string)((len=3) "app"),
74+
// ProcID: (*string)(<nil>),
75+
// MsgID: (*string)(<nil>),
76+
// Message: (*string)((len=4) "Test")
77+
// }
78+
// })
79+
}
80+
81+
func Example_withtimezone_and_year() {
82+
cet, _ := time.LoadLocation("CET")
83+
i := []byte(`<13>Jan 30 02:08:03 host app: Test`)
84+
p := NewParser(WithTimezone(cet), WithYear(Year{YYYY: 1987}))
85+
m, _ := p.Parse(i)
86+
output(m)
87+
// Output:
88+
// (*rfc3164.SyslogMessage)({
89+
// Base: (syslog.Base) {
90+
// Facility: (*uint8)(1),
91+
// Severity: (*uint8)(5),
92+
// Priority: (*uint8)(13),
93+
// Timestamp: (*time.Time)(1987-01-30 03:08:03 +0100 CET),
94+
// Hostname: (*string)((len=4) "host"),
95+
// Appname: (*string)((len=3) "app"),
96+
// ProcID: (*string)(<nil>),
97+
// MsgID: (*string)(<nil>),
98+
// Message: (*string)((len=4) "Test")
99+
// }
100+
// })
101+
}
102+
55103
func Example_besteffort() {
56104
i := []byte(`<13>Dec 2 16:31:03 -`)
57105
p := NewParser(WithBestEffort())

0 commit comments

Comments
 (0)