File tree Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ type machine struct {
35
35
bestEffort bool
36
36
yyyy int
37
37
rfc3339 bool
38
+ loc * time.Location
38
39
}
39
40
40
41
// NewMachine creates a new FSM able to parse RFC3164 syslog messages.
@@ -58,10 +59,19 @@ func (m *machine) HasBestEffort() bool {
58
59
return m .bestEffort
59
60
}
60
61
62
+ // WithYear sets the year for the Stamp timestamp of the RFC 3164 syslog message.
61
63
func (m * machine ) WithYear (o YearOperator ) {
62
64
m .yyyy = YearOperation {o }.Operate ()
63
65
}
64
66
67
+ // WithTimezone sets the time zone for the Stamp timestamp of the RFC 3164 syslog message.
68
+ func (m * machine ) WithTimezone (loc * time.Location ) {
69
+ m .loc = loc
70
+ }
71
+
72
+ // WithRFC3339 enables ability to ALSO match RFC3339 timestamps.
73
+ //
74
+ // Notice this does not disable the default and correct timestamps - ie., Stamp timestamps.
65
75
func (m * machine ) WithRFC3339 () {
66
76
m .rfc3339 = true
67
77
}
@@ -1153,6 +1163,9 @@ func (m *machine) Parse(input []byte) (syslog.Message, error) {
1153
1163
}
1154
1164
} else {
1155
1165
output .timestamp = t .AddDate (m .yyyy , 0 , 0 )
1166
+ if m .loc != nil {
1167
+ output .timestamp = output .timestamp .In (m .loc )
1168
+ }
1156
1169
output .timestampSet = true
1157
1170
}
1158
1171
Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ action set_timestamp {
44
44
fgoto fail;
45
45
} else {
46
46
output.timestamp = t.AddDate(m.yyyy, 0, 0)
47
+ if m.loc != nil {
48
+ output.timestamp = output.timestamp.In(m.loc)
49
+ }
47
50
output.timestampSet = true
48
51
}
49
52
}
@@ -167,6 +170,7 @@ type machine struct {
167
170
bestEffort bool
168
171
yyyy int
169
172
rfc3339 bool
173
+ loc *time.Location
170
174
}
171
175
172
176
// NewMachine creates a new FSM able to parse RFC3164 syslog messages.
@@ -196,10 +200,19 @@ func (m *machine) HasBestEffort() bool {
196
200
return m.bestEffort
197
201
}
198
202
203
+ // WithYear sets the year for the Stamp timestamp of the RFC 3164 syslog message.
199
204
func (m *machine) WithYear(o YearOperator) {
200
205
m.yyyy = YearOperation{o}.Operate()
201
206
}
202
207
208
+ // WithTimezone sets the time zone for the Stamp timestamp of the RFC 3164 syslog message.
209
+ func (m *machine) WithTimezone(loc *time.Location) {
210
+ m.loc = loc
211
+ }
212
+
213
+ // WithRFC3339 enables ability to ALSO match RFC3339 timestamps.
214
+ //
215
+ // Notice this does not disable the default and correct timestamps - ie., Stamp timestamps.
203
216
func (m *machine) WithRFC3339() {
204
217
m.rfc3339 = true
205
218
}
Original file line number Diff line number Diff line change 1
1
package rfc3164
2
2
3
3
import (
4
+ "time"
5
+
4
6
syslog "github.com/influxdata/go-syslog/v2"
5
7
)
6
8
@@ -21,12 +23,12 @@ func WithYear(o YearOperator) syslog.MachineOption {
21
23
}
22
24
23
25
// WithTimezone sets the strategy to decide the timezone to apply to the Stamp timestamp of RFC 3164.
24
- // func WithTimezone(loc time.Location) syslog.MachineOption {
25
- // return func(m syslog.Machine) syslog.Machine {
26
- // m.(*machine).WithTimezone(loc)
27
- // return m
28
- // }
29
- // }
26
+ func WithTimezone (loc * time.Location ) syslog.MachineOption {
27
+ return func (m syslog.Machine ) syslog.Machine {
28
+ m .(* machine ).WithTimezone (loc )
29
+ return m
30
+ }
31
+ }
30
32
31
33
// todo > WithStrictHostname() option - see RFC3164 page 10
32
34
// WithStrictHostname tells the parser to match the hostnames strictly as per RFC 3164 recommentations.
You can’t perform that action at this time.
0 commit comments