Beispiel #1
0
func main() {
	log.SetSeverities(log.INFO | log.WARN)
	log.Info("Severity: will print info.")
	log.Warn("Severity: will print warn.")
	log.Debug("Severity: won't print debug.")

	log.SetMinMaxSeverity(log.TRACE, log.INFO)
	log.Trace("Severity: will print trace.")
	log.Debug("Severity: will print debug.")
	log.Info("Severity: will print info.")
	log.Warn("Severity: won't print warn.")
}
Beispiel #2
0
func init() {
	// default config file
	config_file := "getcvmlist.conf"
	if len(os.Args) == 2 {
		config_file = os.Args[1]
	}
	conf_data, err := ioutil.ReadFile(config_file)
	if err != nil {
		fmt.Printf("read config file fail : %s\n", err)
		os.Exit(1)
	}
	if err := json.Unmarshal(conf_data, &cgw_conf); err != nil {
		fmt.Printf("decode config file fail : %s\n", err)
		os.Exit(1)
	}
	// use default port if needed
	if cgw_conf.ListenPort <= 0 {
		cgw_conf.ListenPort = 20487
	}
	fmt.Println(cgw_conf.Gz)
	fmt.Println(cgw_conf.Sh)
	fmt.Println(cgw_conf.Hk)
	fmt.Println(cgw_conf.Ca)
	fmt.Println("listen port : ", cgw_conf.ListenPort)
	fmt.Println("log file : ", cgw_conf.Log.File)
	fmt.Println("log level: ", cgw_conf.Log.Level)
	logFile, err := os.OpenFile(cgw_conf.Log.File, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	if err != nil {
		fmt.Printf("open log file %s fail, err : %s\n", cgw_conf.Log.File, err)
		os.Exit(1)
	}
	log.SetOutput(logFile)
	log.SetFormatter(log.NewStdFormatter("%{Date} %{Time \"15:04:05.000000\"} %{severity}" + " %{File}:%{Line}:%{Function} %{Message}"))
	log.SetMinMaxSeverity(log.Severity(cgw_conf.Log.Level), log.PANIC)
	runtime.GOMAXPROCS(runtime.NumCPU())
}