-
Notifications
You must be signed in to change notification settings - Fork 70
/
log_match_finder.go
51 lines (38 loc) · 1.06 KB
/
log_match_finder.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
package recipes
import (
"context"
"path/filepath"
log "github.com/sirupsen/logrus"
"github.com/newrelic/newrelic-cli/internal/install/types"
)
type LogMatchFinder struct{}
type LogMatchFinderDefinition interface {
GetPaths(context.Context, []*types.OpenInstallationRecipe) []types.OpenInstallationLogMatch
}
func NewLogMatchFinder() LogMatchFinderDefinition {
f := LogMatchFinder{}
return &f
}
func (f *LogMatchFinder) GetPaths(ctx context.Context, recipes []*types.OpenInstallationRecipe) []types.OpenInstallationLogMatch {
fileMatches := []types.OpenInstallationLogMatch{}
for _, r := range recipes {
for _, l := range r.LogMatch {
match, _ := matchLogFilesFromRecipe(l)
if match {
fileMatches = append(fileMatches, l)
}
}
}
return fileMatches
}
func matchLogFilesFromRecipe(matcher types.OpenInstallationLogMatch) (bool, []string) {
matches, err := filepath.Glob(matcher.File)
if err != nil {
log.Errorf("error matching logfiles: %s", err)
return false, nil
}
if len(matches) > 0 {
return true, matches
}
return false, nil
}