forked from DataDog/datadog-agent
/
runtime_setting_log_level.go
55 lines (47 loc) · 1.51 KB
/
runtime_setting_log_level.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package settings
import (
"github.com/StackVista/stackstate-agent/pkg/config"
"github.com/StackVista/stackstate-agent/pkg/util/log"
)
// LogLevelRuntimeSetting wraps operations to change log level at runtime.
type LogLevelRuntimeSetting struct {
ConfigKey string
}
// Description returns the runtime setting's description
func (l LogLevelRuntimeSetting) Description() string {
return "Set/get the log level, valid values are: trace, debug, info, warn, error, critical and off"
}
// Hidden returns whether or not this setting is hidden from the list of runtime settings
func (l LogLevelRuntimeSetting) Hidden() bool {
return false
}
// Name returns the name of the runtime setting
func (l LogLevelRuntimeSetting) Name() string {
return "log_level"
}
// Get returns the current value of the runtime setting
func (l LogLevelRuntimeSetting) Get() (interface{}, error) {
level, err := log.GetLogLevel()
if err != nil {
return "", err
}
return level.String(), nil
}
// Set changes the value of the runtime setting
func (l LogLevelRuntimeSetting) Set(v interface{}) error {
logLevel := v.(string)
err := config.ChangeLogLevel(logLevel)
if err != nil {
return err
}
key := "log_level"
if l.ConfigKey != "" {
key = l.ConfigKey
}
config.Datadog.Set(key, logLevel)
return nil
}