From 690ee0a813bb959394e2c43936bf921bca3e6842 Mon Sep 17 00:00:00 2001 From: joshblakeley Date: Thu, 12 Oct 2017 16:17:07 +0100 Subject: [PATCH] logging output level available as config option --- config/config.go | 1 + main.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/config/config.go b/config/config.go index 428afd0da24e..30619b2f093d 100644 --- a/config/config.go +++ b/config/config.go @@ -242,6 +242,7 @@ type Config struct { ReloadWaitTime int `bson:"reload_wait_time" json:"reload_wait_time"` ProxySSLInsecureSkipVerify bool `json:"proxy_ssl_insecure_skip_verify"` ProxyDefaultTimeout int `json:"proxy_default_timeout"` + LogLevel string `json:"log_level"` } type CertData struct { diff --git a/main.go b/main.go index 5cef3ad149ba..0e8d8b23fc81 100644 --- a/main.go +++ b/main.go @@ -779,6 +779,23 @@ func initialiseSystem(arguments map[string]interface{}) error { afterConfSetup(&config.Global) } + if os.Getenv("TYK_LOGLEVEL") == "" && arguments["--debug"] == false { + switch strings.ToLower(config.Global.LogLevel) { + case "", "info": + //defualt, do nothing + case "error": + log.Level = logrus.ErrorLevel + case "warn": + log.Level = logrus.WarnLevel + case "debug": + log.Level = logrus.DebugLevel + default: + log.WithFields(logrus.Fields{ + "prefix": "main", + }).Fatal("Invalid log level in config, must be error, warn or debug.") + } + } + if config.Global.Storage.Type != "redis" { log.WithFields(logrus.Fields{ "prefix": "main",