-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathparse.go
75 lines (64 loc) · 1.69 KB
/
parse.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//go:generate ldetool --package parsers --go-string parsers.lde
package parsers
// Event is the interface used to extract an event from a log line.
type Event interface {
Extract(line string) (bool, error)
}
// Parse a log line from any source. Typically it's best to use a targeted parser
// such as ParseLambda() or ParseHeroku(). Returns true if an event was successfully parsed.
func Parse(line string) (Event, bool) {
events := []Event{
&AWSLambdaStart{},
&AWSLambdaReportInit{},
&AWSLambdaReport{},
&AWSLambdaEnd{},
&AWSLambdaTimeout{},
&Syslog{},
}
for _, e := range events {
if ok, _ := e.Extract(line); ok {
return e, true
}
}
return nil, false
}
// ParseLambda parses a log line from AWS Lambda. Returns true if an event was successfully parsed.
func ParseLambda(line string) (Event, bool) {
events := []Event{
&AWSLambdaStart{},
&AWSLambdaReportInit{},
&AWSLambdaReport{},
&AWSLambdaEnd{},
&AWSLambdaTimeout{},
}
for _, e := range events {
if ok, _ := e.Extract(line); ok {
return e, true
}
}
return nil, false
}
// ParseHeroku parses a log line from Heroku. You should first parse the syslog line from Heroku
// using Syslog, and then ParseHeroku() for the platform specific message.
// Returns true if an event was successfully parsed.
func ParseHeroku(line string) (Event, bool) {
events := []Event{
&HerokuDeploy{},
&HerokuRollback{},
&HerokuBuild{},
&HerokuRelease{},
&HerokuProcessExit{},
&HerokuProcessStart{},
&HerokuStateChange{},
&HerokuProcessListening{},
&HerokuConfigSet{},
&HerokuConfigRemove{},
&HerokuScale{},
}
for _, e := range events {
if ok, _ := e.Extract(line); ok {
return e, true
}
}
return nil, false
}