diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 077eed670..edf9c4bc2 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -59,14 +59,11 @@ const ( var ( cfgDir = flag.String("config_dir", utils.CONFIG_DIR, "Configuration directory path.") version = flag.Bool("version", false, "Prints the application version.") - raterEnabled = flag.Bool("rater", false, "Enforce starting of the rater daemon overwriting config") - schedEnabled = flag.Bool("scheduler", false, "Enforce starting of the scheduler daemon .overwriting config") - cdrsEnabled = flag.Bool("cdrs", false, "Enforce starting of the cdrs daemon overwriting config") pidFile = flag.String("pid", "", "Write pid file") cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") scheduledShutdown = flag.String("scheduled_shutdown", "", "shutdown the engine after this duration") singlecpu = flag.Bool("singlecpu", false, "Run on single CPU core") - logLevel = flag.Int("log_level", 8, "Log level (2-alert to 9-debug)") + logLevel = flag.Int("log_level", -1, "Log level (0-emergency to 7-debug)") cfg *config.CGRConfig smRpc *v1.SessionManagerV1 @@ -569,24 +566,20 @@ func main() { exitChan <- true }() } - utils.Logger.SetLogLevel(*logLevel) + cfg, err = config.NewCGRConfigFromFolder(*cfgDir) if err != nil { - utils.Logger.Crit(fmt.Sprintf("Could not parse config: %s exiting!", err)) + log.Fatalf("Could not parse config: ", err) return } + lgLevel := cfg.LogLevel + if *logLevel != -1 { // Modify the log level if provided by command arguments + lgLevel = *logLevel + } + utils.Logger.SetLogLevel(lgLevel) config.SetCgrConfig(cfg) // Share the config object cache.NewCache(cfg.CacheConfig) - if *raterEnabled { - cfg.RALsEnabled = *raterEnabled - } - if *schedEnabled { - cfg.SchedulerEnabled = *schedEnabled - } - if *cdrsEnabled { - cfg.CDRSEnabled = *cdrsEnabled - } var ratingDb engine.RatingStorage var accountDb engine.AccountingStorage var loadDb engine.LoadStorage diff --git a/config/config.go b/config/config.go index b9738ed5d..a7acb3ed2 100644 --- a/config/config.go +++ b/config/config.go @@ -220,6 +220,7 @@ type CGRConfig struct { HttpFailedDir string // Directory path where we store failed http requests MaxCallDuration time.Duration // The maximum call duration (used by responder when querying DerivedCharging) // ToDo: export it in configuration file LockingTimeout time.Duration // locking mechanism timeout to avoid deadlocks + LogLevel int // system wide log level, nothing higher than this will be logged RALsEnabled bool // start standalone server (no balancer) RALsBalancer string // balancer address host:port RALsCDRStatSConns []*HaPoolConfig // address where to reach the cdrstats service. Empty to disable stats gathering <""|internal|x.y.z.y:1234> @@ -755,6 +756,9 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error { return err } } + if jsnGeneralCfg.Log_level != nil { + self.LogLevel = *jsnGeneralCfg.Log_level + } } if jsnCacheCfg != nil { diff --git a/config/config_defaults.go b/config/config_defaults.go index 350927c97..f2868793f 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -44,7 +44,8 @@ const CGRATES_CFG_JSON = ` "response_cache_ttl": "0s", // the life span of a cached response "internal_ttl": "2m", // maximum duration to wait for internal connections before giving up "locking_timeout": "5s", // timeout internal locks to avoid deadlocks - "cache_dump_dir": "", // cache dump for faster start (leave empty to disable) + "cache_dump_dir": "", // cache dump for faster start (leave empty to disable) + "log_level": 6, // control the level of messages logged (0-emerg to 7-debug) }, diff --git a/config/config_json_test.go b/config/config_json_test.go index bd7a52b3a..92a351e4f 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -54,7 +54,8 @@ func TestDfGeneralJsonCfg(t *testing.T) { Reply_timeout: utils.StringPointer("2s"), Response_cache_ttl: utils.StringPointer("0s"), Internal_ttl: utils.StringPointer("2m"), - Locking_timeout: utils.StringPointer("5s")} + Locking_timeout: utils.StringPointer("5s"), + Log_level: utils.IntPointer(utils.LOGLEVEL_INFO)} if gCfg, err := dfCgrJsonCfg.GeneralJsonCfg(); err != nil { t.Error(err) } else if !reflect.DeepEqual(eCfg, gCfg) { diff --git a/config/libconfig_json.go b/config/libconfig_json.go index d85cf53dd..5fe70d3af 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -36,6 +36,7 @@ type GeneralJsonCfg struct { Response_cache_ttl *string Internal_ttl *string Locking_timeout *string + Log_level *int } // Listen config section diff --git a/utils/logger.go b/utils/logger.go index 3acc9460a..6a958bcc8 100644 --- a/utils/logger.go +++ b/utils/logger.go @@ -43,29 +43,28 @@ func init() { type LoggerInterface interface { SetSyslog(log *syslog.Writer) SetLogLevel(level int) - GetSyslog() *syslog.Writer - - Alert(m string) error Close() error - Crit(m string) error - Debug(m string) error Emerg(m string) error + Alert(m string) error + Crit(m string) error Err(m string) error - Info(m string) error - Notice(m string) error Warning(m string) error + Notice(m string) error + Info(m string) error + Debug(m string) error } +// log severities following rfc3164 const ( - LOGLEVEL_DEBUG = 9 - LOGLEVEL_INFO = 8 - LOGLEVEL_NOTICE = 7 - LOGLEVEL_WARNING = 6 - LOGLEVEL_ERROR = 5 - LOGLEVEL_CRITICAL = 4 - LOGLEVEL_EMERGENCY = 3 - LOGLEVEL_ALERT = 2 + LOGLEVEL_EMERGENCY = iota + LOGLEVEL_ALERT + LOGLEVEL_CRITICAL + LOGLEVEL_ERROR + LOGLEVEL_WARNING + LOGLEVEL_NOTICE + LOGLEVEL_INFO + LOGLEVEL_DEBUG ) // Logs to standard output