-
Notifications
You must be signed in to change notification settings - Fork 111
/
service.go
46 lines (37 loc) · 1.25 KB
/
service.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
package config
import (
"time"
log "github.com/sirupsen/logrus"
es "github.com/chef/automate/components/es-sidecar-service/pkg/elastic"
"github.com/chef/automate/lib/tls/certs"
)
type watcherConfig struct {
CheckInterval time.Duration `mapstructure:"interval"`
WarningBytesFree int64 `mapstructure:"warning_bytes"`
CriticalBytesFree int64 `mapstructure:"critical_bytes"`
}
// Service defines the available configuration options for this service
type Service struct {
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
LogLevel string `mapstructure:"log_level"`
ElasticsearchURL string `mapstructure:"elasticsearch_url"`
WatcherConfig watcherConfig `mapstructure:"watcher"`
certs.TLSConfig `mapstructure:"tls"`
BackupsConfig es.BackupsConfig `mapstructure:"backups"`
}
// SetLogLevel sets the log level for the service
func (s *Service) SetLogLevel() {
if s.LogLevel == "" {
return
}
log.WithFields(log.Fields{
"level": s.LogLevel,
}).Info("Setting log level")
level, err := log.ParseLevel(s.LogLevel)
if err != nil {
log.WithField("level", s.LogLevel).WithError(err).Error("Using default level 'info'")
return
}
log.SetLevel(level)
}