forked from goss-org/goss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.go
32 lines (29 loc) · 702 Bytes
/
logs.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
package goss
import (
"fmt"
"log"
"os"
"github.com/goss-org/goss/util"
"github.com/hashicorp/logutils"
)
func setLogLevel(c *util.Config) error {
filter := &logutils.LevelFilter{
Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"},
MinLevel: logutils.LogLevel("WARN"),
Writer: os.Stderr,
}
logLevelFound := false
for _, lvl := range filter.Levels {
if string(lvl) == c.LogLevel {
logLevelFound = true
break
}
}
if !logLevelFound {
return fmt.Errorf("Unsupported log level: %s", c.LogLevel)
}
filter.MinLevel = logutils.LogLevel(c.LogLevel)
log.SetOutput(filter)
log.Printf("[DEBUG] Setting log level to %v", c.LogLevel)
return nil
}