예제 #1
0
파일: main.go 프로젝트: yuwnloyblog/yundis
func main() {
	args := os.Args
	if len(args) <= 1 {
		fmt.Println("Please specify the yundis.properties file.")
		return
	}
	configFile := args[1]
	fmt.Printf("Load the config file : %s.\n", configFile)
	props := utils.Properties{}
	err := props.LoadPropertyFile(configFile)
	if err != nil {
		log.Errorf("Load %s error: %s", configFile, err)
	} else {
		mylogutil.InitLogger(props)
		log.Info("Success to load the " + configFile)
		serverId, err := props.GetInt("server.id")
		if err != nil {
			log.Errorf("Read the server.id error:%s", err)
			return
		}
		serverHost, err := props.GetString("server.host")
		if err != nil {
			log.Errorf("Read the server.host error:%s", err)
			return
		}
		serverPort, err := props.GetInt("server.port")
		if err != nil {
			log.Errorf("Read the server.port error:%s", err)
			return
		}
		slotCount, err := props.GetInt("server.slots")
		if err != nil {
			log.Errorf("Read the server.slots error: %s", err)
			return
		}
		redisServer, err := props.GetString("redis.host")
		if err != nil {
			log.Errorf("Read the redis.server error:%s", err)
			return
		}
		redisPort, err := props.GetInt("redis.port")
		if err != nil {
			log.Errorf("Read the redis.port error:%s", err)
			return
		}
		zkconnect, err := props.GetString("zookeeper.connect")
		if err != nil {
			log.Errorf("Read the zookeeper.connect error:%s", err)
			return
		}

		zkAddress := strings.Split(zkconnect, ",")
		ser := &server.YundisServer{
			Id:        serverId,
			Host:      serverHost,
			Port:      serverPort,
			RedisHost: redisServer,
			RedisPort: redisPort,
			ZkAddress: zkAddress,
			SlotCount: slotCount,
		}
		log.Info("Begin to start the yundis server.")
		ser.Start()
	}

	//time.Sleep(time.Second*100)
}
예제 #2
0
파일: log.go 프로젝트: yuwnloyblog/yundis
//InitLogger
func InitLogger(props utils.Properties) {
	logType := props.GetStringWithDefault("log.type", "sync")
	typeStr := ""
	if logType == "sync" {
		typeStr = `type="sync"`
	} else if logType == "asynctimer" {
		asyncInterval := props.GetIntWithDefault("log.asyncinterval", 5000000)
		typeStr = `type="asynctimer" asyncinterval="` + strconv.Itoa(asyncInterval) + `"`
	}
	minLevel := props.GetStringWithDefault("log.minlevel", "info")
	maxlevel := props.GetStringWithDefault("log.maxlevel", "error")
	logDir := props.GetStringWithDefault("log.dirs", "./log")
	segmentBytes := props.GetIntWithDefault("log.segment.bytes", 53687092)
	segmentRolls := props.GetIntWithDefault("log.segment.rolls", 5)

	logConfig := `
		<seelog ` + typeStr + ` minlevel="` + minLevel + `" maxlevel="` + maxlevel + `">
				<outputs formatid="main">
				    <console/>
						<rollingfile type="size" filename="` + logDir + `/server.log" maxsize="` + strconv.Itoa(segmentBytes) + `" maxrolls="` + strconv.Itoa(segmentRolls) + `"/>
					  <filter levels="error">
								<file path="` + logDir + `/error.log"/>
						</filter>
				</outputs>
				<formats>
						<format id="main" format="%Date(2006 Jan 02 3:04:05.000000000 PM MST) [%Level] %Msg%n"/>
				</formats>
		</seelog>
	`
	mylogger, err := log.LoggerFromConfigAsString(logConfig)
	//fmt.Println(logConfig)
	//mylogger, err := log.LoggerFromConfigAsFile("../config/log.xml")
	if err != nil {
		fmt.Println("load seelog config fail:", err)
	}
	log.ReplaceLogger(mylogger)
}