-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.go
More file actions
36 lines (27 loc) · 764 Bytes
/
Copy pathconfig.go
File metadata and controls
36 lines (27 loc) · 764 Bytes
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
package logfilter
import (
"strings"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func LoadConfig(config string) (*LogFilter, error) {
lf := NewLogFilter()
// Allow empty configs
if len(strings.TrimSpace(config)) == 0 {
return lf, nil
}
// Each log level mapping is separated by comma
for _, s := range strings.Split(config, ",") {
// Each file path is separated from log level by a ":"
pathAndLevel := strings.Split(strings.TrimSpace(s), ":")
if len(pathAndLevel) != 2 {
return nil, errors.Errorf("unexpected syntax in filter: %s", s)
}
l, err := logrus.ParseLevel(pathAndLevel[1])
if err != nil {
return nil, errors.Wrap(err, "unable to parse log level")
}
lf.SetLevel(l, pathAndLevel[0])
}
return lf, nil
}