func main() { var host = flag.String("host", "", "Server listen host, default 0.0.0.0") var port = flag.Int("port", 80, "Server listen port, default 80") var url = flag.String("url", "", "Click open url") var nst = flag.String("nst", "", "Notify start time, format: YYYY-mm-dd HH:MM") var nvt = flag.String("nvt", "", "Notify over time, format as start time") var cpu = flag.Int("cpu", 0, "Go runtime max process") var logpath = flag.String("logpath", "./", "Log path") var logfile = flag.String("logfile", "", "Log filename") var nextmin = flag.Int("nextmin", NextMinute, "Next request duration(minute)") flag.Parse() if *logfile != "" { if logger, err := logging.NewHourRotationLogger(*logfile, *logpath, LOGFILE_SUFFIX); err != nil { panic(err) } else { logging.SetDefaultLogger(logger) logging.SetPrefix("BWService") } } if *cpu > 0 { runtime.GOMAXPROCS(*cpu) } loc, err := time.LoadLocation("Asia/Shanghai") if err != nil { panic(err) } if t, err := time.ParseInLocation("2006-01-02 15:04", *nst, loc); err != nil { panic(err) } else { NotifyStartTime = t } if t, err := time.ParseInLocation("2006-01-02 15:04", *nvt, loc); err != nil { panic(err) } else { NotifyEndTime = t } if *url == "" { panic(*url) } else { ClickURL = *url } if *nextmin > 0 { NextMinute = *nextmin } var addr = net.JoinHostPort(*host, strconv.Itoa(*port)) http.HandleFunc("/patrol", Patrol) logging.Info("[%s] (%s) - (%s) => %s, %d\n", addr, NotifyStartTime.String(), NotifyEndTime.String(), ClickURL, NextMinute) if err := http.ListenAndServe(addr, nil); err != nil { logging.Error("%s", err.Error()) } }
func (self *Entry) Error(format string, v ...interface{}) { logging.Error(self.formatHead(format), v...) }