func initLog() { log.SetName("banshee") if *debug { log.SetLevel(log.DEBUG) } goVs := runtime.Version() nCPU := runtime.GOMAXPROCS(-1) vers := version.Version log.Debug("banshee%s %s %d cpu", vers, goVs, nCPU) }
func main() { // Arguments fileName := flag.String("c", "config.json", "config file") debug := flag.Bool("d", false, "debug mode") vers := flag.Bool("v", false, "version") flag.Parse() // Version if *vers { fmt.Fprintln(os.Stdout, version.Version) os.Exit(1) } // Logging log.SetName("banshee") if *debug { log.SetLevel(log.DEBUG) } log.Debug("using %s, max %d cpu", runtime.Version(), runtime.GOMAXPROCS(-1)) // Config cfg := config.New() if flag.NFlag() == 0 || (flag.NFlag() == 1 && *debug == true) { log.Warn("no config file specified, using default..") } else { err := cfg.UpdateWithJSONFile(*fileName) if err != nil { log.Fatal("failed to load %s, %s", *fileName, err) } } // Storage options := &storage.Options{ NumGrid: cfg.Period[0], GridLen: cfg.Period[1], } db, err := storage.Open(cfg.Storage.Path, options) if err != nil { log.Fatal("failed to open %s: %v", cfg.Storage.Path, err) } // Cleaner cleaner := cleaner.New(db, cfg.Period[0]*cfg.Period[1]) go cleaner.Start() // Filter filter := filter.New() filter.Init(db) // Alerter alerter := alerter.New(cfg, db, filter) alerter.Start() // Webapp go webapp.Start(cfg, db) // Detector detector := detector.New(cfg, db, filter) detector.Out(alerter.In) detector.Start() }
// initLog initializes logging. func initLog() { if *debug { log.SetLevel(log.DEBUG) } }