|
1 | 1 | package rfc3164
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + // "time" |
| 5 | + |
| 6 | + "time" |
| 7 | + |
4 | 8 | "github.com/davecgh/go-spew/spew"
|
5 | 9 | )
|
6 | 10 |
|
@@ -52,6 +56,50 @@ func Example_currentyear() {
|
52 | 56 | // })
|
53 | 57 | }
|
54 | 58 |
|
| 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 | + |
55 | 103 | func Example_besteffort() {
|
56 | 104 | i := []byte(`<13>Dec 2 16:31:03 -`)
|
57 | 105 | p := NewParser(WithBestEffort())
|
|
0 commit comments