Пример #1
0
func main() {
	if err := logger.SetupLogWithConf("./log.json"); err != nil {
		panic(err)
	}
	defer logger.Close()

	var name = "shengkehua"
	for {
		logger.Trace("log4go by %s", name)
		logger.Debug("log4go by %s", name)
		logger.Info("log4go by %s", name)
		logger.Warn("log4go by %s", name)
		logger.Error("log4go by %s", name)
		logger.Fatal("log4go by %s", name)

		time.Sleep(time.Second * 1)
	}
}
Пример #2
0
func main() {
	// init log
	if err := logger.SetupLogWithConf(logFile); err != nil {
		fmt.Printf("log init fail: %s\n", err.Error())
		return
	}
	defer logger.Close()

	//read config file
	if err := gcfg.ReadFileInto(&cfg, confFile); err != nil {
		logger.Error("read conf failed, err:%s", err.Error())
		return
	}
	logger.Info("logFile=%v, confFile=%v, cfg=%v", logFile, confFile, cfg)

	//read data file
	path := "../data/hadoop.txt"
	logger.Debug("read file path=%v", path)
	file, err := os.Open(path)
	if err != nil {
		logger.Error("open file:%s fail, err=%v", path, err)
	}
	defer file.Close()

	//redis
	st := time.Now()
	conn, err := redis.DialTimeout("tcp", "10.10.16.99:6380", 0, 1*time.Second, 1*time.Second)
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		str := strings.Split(scanner.Text(), "\t")
		addr, err := parseLine(str)
		if err == nil {
			//logger.Debug("add=%v", addr)
			buffer, _ := proto.Marshal(addr)
			key := "goaddr" + str[0]
			conn.Do("SET", key, buffer)
		}
	}
	fmt.Println("consume time:", time.Since(st))

	if err := scanner.Err(); err != nil {
		logger.Error("read file:%s error, err=%v", path, err)
	}
}