func init() { // Try to have highest performance. runtime.GOMAXPROCS(runtime.NumCPU()) // Set application log level. beego.SetLevel(beego.LevelTrace) // Initialize log file. os.Mkdir("./log", os.ModePerm) // Compute log file name as format '<year>-<month>-<day>.txt', eg.'2013-5-6.txt'. logName := fmt.Sprintf("./log/%d-%d-%d.txt", time.Now().Year(), time.Now().Month(), time.Now().Day()) // Open or create log file. var fl *os.File var err error if utils.IsExist(logName) { fl, err = os.OpenFile(logName, os.O_RDWR|os.O_APPEND, 0644) } else { fl, err = os.Create(logName) } if err != nil { beego.Trace("Failed to init log file ->", err) return } beego.Info("Go Walker", VERSION) beego.SetLogger(log.New(fl, "", log.Ldate|log.Ltime)) }
// shutdownCheck returns true if server detects shutdown signal. func shutdownCheck() bool { if utils.IsExist("SHUTDOWN.SIGN") { os.Remove("SHUTDOWN.SIGN") beego.Info("Detected SHUTDOWN.SIGN") if beego.Level() == beego.LevelInfo { fmt.Println("Detected SHUTDOWN.SIGN") } return true } return false }