mirror of
https://github.com/eosswedenorg/thalos
synced 2026-07-02 11:43:40 +02:00
cmd/thalos/main.go: Add "level" cli flag to make it possible for user to specify log level.
This commit is contained in:
parent
fb6cfb9fa6
commit
b364ce56d8
1 changed files with 17 additions and 0 deletions
|
|
@ -163,6 +163,14 @@ func getChain(def string) string {
|
||||||
return def
|
return def
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LogLevels() []string {
|
||||||
|
list := []string{}
|
||||||
|
for _, lvl := range log.AllLevels {
|
||||||
|
list = append(list, lvl.String())
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
var chainInfo *eos.InfoResp
|
var chainInfo *eos.InfoResp
|
||||||
|
|
@ -174,6 +182,7 @@ func main() {
|
||||||
configFile := getopt.StringLong("config", 'c', "./config.yml", "Config file to read", "file")
|
configFile := getopt.StringLong("config", 'c', "./config.yml", "Config file to read", "file")
|
||||||
pidFile := getopt.StringLong("pid", 'p', "", "Where to write process id", "file")
|
pidFile := getopt.StringLong("pid", 'p', "", "Where to write process id", "file")
|
||||||
logFile := getopt.StringLong("log", 'l', "", "Path to log file", "file")
|
logFile := getopt.StringLong("log", 'l', "", "Path to log file", "file")
|
||||||
|
logLevel := getopt.EnumLong("level", 'L', LogLevels(), "info", "Log level to use")
|
||||||
|
|
||||||
getopt.Parse()
|
getopt.Parse()
|
||||||
|
|
||||||
|
|
@ -210,6 +219,14 @@ func main() {
|
||||||
conf.Log.Filename = path.Base(*logFile)
|
conf.Log.Filename = path.Base(*logFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lvl, err := log.ParseLevel(*logLevel)
|
||||||
|
if err == nil {
|
||||||
|
log.WithField("value", lvl).Info("Setting log level")
|
||||||
|
log.SetLevel(lvl)
|
||||||
|
} else {
|
||||||
|
log.WithError(err).Warn("Failed to parse level")
|
||||||
|
}
|
||||||
|
|
||||||
if len(conf.Log.Filename) > 0 {
|
if len(conf.Log.Filename) > 0 {
|
||||||
stdWriter, err := NewRotatingFileFromConfig(conf.Log, "info")
|
stdWriter, err := NewRotatingFileFromConfig(conf.Log, "info")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue