Exemplo n.º 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")
}
Exemplo n.º 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)
}
Exemplo n.º 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())
}
Exemplo n.º 4
0
func SetLog() {
	w := log.NewFileWriter()
	/*
	   %Y  year    (eg: 2014)
	   %M  month   (eg: 07)
	   %D  day     (eg: 05)
	   %H  hour    (eg: 18)
	   %m  minute  (eg: 29)

	   notice: No second's variable
	*/
	w.SetPathPattern("/tmp/logs/error%Y%M%D%H%m.log")

	log.Register(w)
	log.SetLevel(log.ERROR)
}