Compare commits
4 Commits
master
...
logparser-
Author | SHA1 | Date |
---|---|---|
Greg Linton | f88f665cd9 | |
Ayrdrie | a2df042d92 | |
Ayrdrie Palmer | c7a72b9a9d | |
Ayrdrie Palmer | 09f884b4f0 |
|
@ -340,6 +340,9 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) {
|
||||||
|
|
||||||
ts, err := time.ParseInLocation(t, v, p.loc)
|
ts, err := time.ParseInLocation(t, v, p.loc)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
if ts.Year() == 0 {
|
||||||
|
ts = ts.AddDate(timestamp.Year(), 0, 0)
|
||||||
|
}
|
||||||
timestamp = ts
|
timestamp = ts
|
||||||
} else {
|
} else {
|
||||||
log.Printf("E! Error parsing %s to time layout [%s]: %s", v, t, err)
|
log.Printf("E! Error parsing %s to time layout [%s]: %s", v, t, err)
|
||||||
|
@ -469,7 +472,6 @@ func (t *tsModder) tsMod(ts time.Time) time.Time {
|
||||||
t.rollover = 0
|
t.rollover = 0
|
||||||
return ts
|
return ts
|
||||||
}
|
}
|
||||||
|
|
||||||
if ts.Equal(t.last) {
|
if ts.Equal(t.last) {
|
||||||
t.dupe = ts
|
t.dupe = ts
|
||||||
}
|
}
|
||||||
|
|
|
@ -1000,3 +1000,20 @@ func TestReplaceTimestampComma(t *testing.T) {
|
||||||
//Convert Nanosecond to milisecond for compare
|
//Convert Nanosecond to milisecond for compare
|
||||||
require.Equal(t, 555, m.Time().Nanosecond()/1000000)
|
require.Equal(t, 555, m.Time().Nanosecond()/1000000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptyYearInTimestamp(t *testing.T) {
|
||||||
|
p := &Parser{
|
||||||
|
Patterns: []string{`%{APPLE_SYSLOG_TIME_SHORT:timestamp:ts-"Jan 2 15:04:05"} %{HOSTNAME} %{APP_NAME:app_name}\[%{NUMBER:pid:int}\]%{GREEDYDATA:message}`},
|
||||||
|
CustomPatterns: `
|
||||||
|
APPLE_SYSLOG_TIME_SHORT %{MONTH} +%{MONTHDAY} %{TIME}
|
||||||
|
APP_NAME [a-zA-Z0-9\.]+
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
require.NoError(t, p.Compile())
|
||||||
|
p.ParseLine("Nov 6 13:57:03 generic iTunes[6504]: info> Scale factor of main display = 2.0")
|
||||||
|
m, err := p.ParseLine("Nov 6 13:57:03 generic iTunes[6504]: objc[6504]: Object descriptor was null.")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, m)
|
||||||
|
require.Equal(t, 2018, m.Time().Year())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue