func init() { Cfg = new(Configs) log.NewLogger(0, "console", `{"level": 0}`) }
func init() { Cfg = newCfg() log.NewLogger(0, "console", `{"level": 0}`) }
func newLogService() { f := "logs.toml" configPath := getUserConfigFile(f) m := multiconfig.NewWithPath(configPath) err := m.Load(Cfg) if err != nil { panic(err) } for _, conf := range Cfg.Logs { if !conf.ENABLE { continue } level, ok := logLevels[conf.LEVEL] if !ok { log.Fatal(4, "Unknown log level: %s", conf.LEVEL) } str := "" switch conf.MODE { case "console": str = fmt.Sprintf(`{"level":%s}`, level) case "file": str = fmt.Sprintf( `{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level, conf.FILE_NAME, conf.LOG_ROTATE, conf.MAX_LINES, 1<<uint(conf.MAX_SIZE_SHIFT), conf.DAILY_ROTATE, conf.MAX_DAYS, ) case "conn": str = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level, conf.RECONNECT_ON_MSG, conf.RECONNECT, conf.PROTOCOL, conf.ADDR) case "smtp": tos, err := json.Marshal(conf.RECEIVERS) if err != nil { log.Error(4, "json.Marshal(conf.RECEIVERS) err %v", err) continue } str = fmt.Sprintf(`{"level":%s,"username":"******","password":"******","host":"%s","sendTos":%s,"subject":"%s"}`, level, conf.USER, conf.PASSWD, conf.HOST, tos, conf.SUBJECT) case "database": str = fmt.Sprintf(`{"level":%s,"driver":"%s","conn":"%s"}`, level, conf.DRIVER, conf.CONN) default: continue } log.Info(str) log.NewLogger(conf.BUFFER_LEN, conf.MODE, str) log.Info("Log Mode: %s(%s)", conf.MODE, conf.LEVEL) } }