Beispiel #1
0
func SetLog() {
	w := log.NewConsoleWriter()
	w.SetColor(true)

	log.Register(w)
	log.SetLevel(log.DEBUG)
	log.SetLayout("2006-01-02 15:04:05")
}
Beispiel #2
0
func SetLog() {
	w1 := log.NewFileWriter()
	w1.SetPathPattern("/tmp/logs/error%Y%M%D%H.log")

	w2 := log.NewConsoleWriter()

	log.Register(w1)
	log.Register(w2)
	log.SetLevel(log.ERROR)
}
Beispiel #3
0
func init() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	if config.Info.FW.On == true {
		w := log4go.NewFileWriter()
		w.SetPathPattern(config.Info.FW.LogPath)
		log4go.Register(w)
	}

	if config.Info.CW.On == true {
		w := log4go.NewConsoleWriter()
		w.SetColor(config.Info.CW.Color)
		log4go.Register(w)
	}

	switch config.Info.Level {
	case "Debug":
		log4go.SetLevel(log4go.DEBUG)

	case "Info":
		log4go.SetLevel(log4go.INFO)

	case "Warning":
		log4go.SetLevel(log4go.WARNING)

	case "Error":
		log4go.SetLevel(log4go.ERROR)

	case "Fatal":
		log4go.SetLevel(log4go.FATAL)

	default:
		log4go.Info("日志配置错误。")
	}

	log4go.Info("服务:%s", NAME)
	log4go.Info("描述: %s", DESCRIPTION)
	log4go.Info("版本号:%s", VERSION)
	log4go.Info("操作系统: %s", runtime.GOOS)
	log4go.Info("CPU: %s", runtime.GOARCH)
	log4go.Info("核心数: %d", runtime.NumCPU())
}