Adding log_level in cgrates.json, not longer starting services from cgr-engine command arguments

This commit is contained in:
DanB
2016-10-25 19:10:47 +02:00
parent 734ad7078d
commit bd0a902005
6 changed files with 31 additions and 32 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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)
},

View File

@@ -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) {

View File

@@ -36,6 +36,7 @@ type GeneralJsonCfg struct {
Response_cache_ttl *string
Internal_ttl *string
Locking_timeout *string
Log_level *int
}
// Listen config section

View File

@@ -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