當前位置: 首頁>>代碼示例>>Golang>>正文


Golang loglib.Error函數代碼示例

本文整理匯總了Golang中logd/loglib.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getLineRecord

/*
* 行數為非負值表示已tail的行數
* 行數為負值則都將從文件末尾開始
* 自動保存的行數隻可能是bufSize的倍數或者文件總行數
 */
func getLineRecord(path string) (line int, fname string) {
	fin, err := os.Open(path)
	if err != nil {
		_, f, l, _ := runtime.Caller(0)
		loglib.Error(fmt.Sprintf("%s:%d open line record `%s` error\n", f, l, path))
		return -1, "" //從最後開始讀
	}
	var txt string
	var lineStr = ""
	//隻讀第一行
	scanner := bufio.NewScanner(fin)
	for scanner.Scan() {
		txt = strings.Trim(scanner.Text(), " ")
		break
	}
	fin.Close()
	parts := strings.Split(txt, " ")
	if len(parts) == 2 {
		fname = parts[0]
		lineStr = parts[1]
	} else {
		lineStr = parts[0]
	}
	line, err = strconv.Atoi(lineStr)
	if err != nil {
		loglib.Error("convert line record error:" + err.Error())
		line = -1
	}
	return line, fname
}
開發者ID:postfix,項目名稱:logd,代碼行數:35,代碼來源:tailer.go

示例2: saveFootPrint

//保存footprint
func (t *TcpReceiver) saveFootPrint() {
	vbytes, err := json.Marshal(t.footPrint)
	if err != nil {
		loglib.Error("marshal footprint error:" + err.Error())
		return
	}
	err = ioutil.WriteFile(t.footPrintFile, vbytes, 0664)
	if err == nil {
		loglib.Info("save footprint success !")
	} else {
		loglib.Error("save footprint error:" + err.Error())
	}
}
開發者ID:postfix,項目名稱:logd,代碼行數:14,代碼來源:tcpReceiver.go

示例3: saveLineRecord

func saveLineRecord(path string, fname string, lineNum int) {
	fout, err := os.Create(path)
	defer fout.Close()
	if err != nil {
		loglib.Error("save line record error: " + err.Error())
		return
	}
	_, err = fmt.Fprintf(fout, "%s %d", fname, lineNum)
	if err != nil {
		loglib.Error("Write line record error" + err.Error())
		return
	}
	loglib.Info("save line record success!")
}
開發者ID:postfix,項目名稱:logd,代碼行數:14,代碼來源:tailer.go

示例4: SaveStatus

func (this *IntegrityChecker) SaveStatus() {
	m := make(map[string]map[string]map[string]map[string]int)
	m["hour_received"] = this.hourReceived
	m["day_received"] = this.dayReceived
	vbytes, err := json.Marshal(m)
	if err != nil {
		loglib.Error("marshal log received error:" + err.Error())
		return
	}
	err = ioutil.WriteFile(this.statusFile, vbytes, 0664)
	if err == nil {
		loglib.Info("save log received success !")
	} else {
		loglib.Error("save log received error:" + err.Error())
	}
}
開發者ID:postfix,項目名稱:logd,代碼行數:16,代碼來源:integrity_checker.go

示例5: Tailling

func (this *Tailler) Tailling(receiveChan chan map[string]string) {
	if this.currFile == "" {
		//兼容老格式,老格式無文件路徑
		this.currFile = this.getLogFileByTime(time.Now())
	}
	var err error
	this.fileHour, err = this.getTimeFromLogName(this.currFile)
	if err != nil {
		loglib.Error("can't get time from current log file:" + this.currFile + "error:" + err.Error())
		os.Exit(1)
	}
	isQuit := false
	for time.Since(this.fileHour).Hours() >= 1 {
		//說明重啟時已經跟記錄行號時不屬於同一個小時了
		isQuit = this.taillingPrevious(this.currFile, this.lineNum, this.fileHour.Format(this.hourStrFmt), receiveChan)
		if isQuit {
			break
		}
		//繼續下一個小時
		this.fileHour = this.fileHour.Add(time.Hour)
		this.currFile = this.getLogFileByTime(this.fileHour)
		this.lineNum = 0
	}
	if !isQuit {
		//處理當前這個小時
		this.taillingCurrent(receiveChan)
	}
	close(receiveChan)
	this.wq.AllDone()
}
開發者ID:postfix,項目名稱:logd,代碼行數:30,代碼來源:tailer.go

示例6: Start

func (this *MongoDbOutputer) Start() {
    wg := &sync.WaitGroup{}
    defer func(){
        if err := recover(); err != nil {
            loglib.Error(fmt.Sprintf("mongodb outputer panic:%v", err))
        }
        if this.session != nil {
            this.session.Close()
        }
        this.wq.AllDone()
    }()

    this.reloadFileCache()
   
    go this.reConnMongoDb()

    wg.Add(this.savers)

    for i:=0; i<this.savers; i++ {
        go this.runParse(i, wg)
    }

    nRetry := this.savers / 6 + 1
    wg.Add(nRetry)
    for i:=0; i<nRetry; i++ {
        go this.retrySave(wg, i)
    }

    wg.Wait()


}
開發者ID:postfix,項目名稱:logd,代碼行數:32,代碼來源:mongodb_outputer.go

示例7: Run

func (lr *LogReceiver) Run() {
	l, err := net.Listen("tcp", fmt.Sprintf(":%d", lr.port))
	if err != nil {
		loglib.Error("[log receiver] " + err.Error())
		return
	}
	defer l.Close()
	for {
		conn, err := l.Accept()
		if err != nil {
			loglib.Error("[log receiver] " + err.Error())
			return
		}
		go lr.handleConnection(conn)
	}

}
開發者ID:postfix,項目名稱:logd,代碼行數:17,代碼來源:log_receiver.go

示例8: extract

func (f *fileOutputer) extract(bp *bytes.Buffer) {
	buf := make([]byte, 4)
	bp.Read(buf)

	l, _ := binary.Uvarint(buf)
	headerLen := int(l)
	//get pack header
	buf = make([]byte, headerLen)
	bp.Read(buf)
	header := tcp_pack.ParseHeader(buf)

	r, err := zlib.NewReader(bp)
	if err != nil {
		loglib.Error("zlib reader Error: " + err.Error())
	} else {
		lines, _ := strconv.Atoi(header["lines"])
		done := false
		if header["done"] == "1" {
			done = true
		}
		f.ic.Add(header["ip"], header["hour"], header["id"], lines, done)

		writerKey := header["ip"] + "_" + header["hour"]
		fout := f.getWriter(f.writers, f.dataDir, writerKey)

		//一頭一尾寫頭信息,節省硬盤
		buf = append(buf, '\n')
		//fout.Write(buf)
		nn, err := io.Copy(fout, r)
		if err != nil {
			loglib.Warning(fmt.Sprintf("save %s_%s_%s error:%s, saved:%d", header["ip"], header["hour"], header["id"], err, nn))
		}
		//fout.Write(buf)

		//單獨存一份header便於查數
		fout = f.getWriter(f.headerWriters, f.headerDir, writerKey)
		n, err := fout.Write(buf)
		if err != nil {
			loglib.Info(fmt.Sprintf("writer header %s %d %s", writerKey, n, err.Error()))
		}

		if done || time.Now().Unix() > f.checkTime.Unix() {
			hourFinish, _ := f.ic.Check()
			for ip, hours := range hourFinish {
				for _, hour := range hours {
					writerKey = ip + "_" + hour
				}
			}
			f.closeWriters(f.writers)
			f.closeWriters(f.headerWriters)
			f.checkTime.Add(2 * time.Minute)
		}

		r.Close()
	}
}
開發者ID:postfix,項目名稱:logd,代碼行數:56,代碼來源:fileOutputer.go

示例9: loadFootPrint

func (t *TcpReceiver) loadFootPrint(fname string) map[string]PackAppear {
	fp := make(map[string]PackAppear)
	if lib.FileExists(fname) {
		vbytes, err := ioutil.ReadFile(fname)
		if err != nil {
			loglib.Error("read footprint file error:" + err.Error())
		} else {
			err = json.Unmarshal(vbytes, &fp)
			if err != nil {
				loglib.Error("unmarshal footprint error:" + err.Error())
			} else {
				loglib.Info("load footprint success !")
			}
		}
	} else {
		loglib.Warning("footprint file " + fname + " not found!")
	}
	return fp
}
開發者ID:postfix,項目名稱:logd,代碼行數:19,代碼來源:tcpReceiver.go

示例10: initConnection

//init conn list from addrMap
func (sc *SingleConnection) initConnection() {
	newConn, err := createSingleConnection(sc.currentAddr)
	if err != nil {
		loglib.Error("init err:" + err.Error())
	} else {
		sc.conn = newConn
	}

	lib.CheckError(err)
}
開發者ID:postfix,項目名稱:logd,代碼行數:11,代碼來源:singleConnection.go

示例11: initMongoDbSession

func initMongoDbSession(mongosAddr string) *mgo.Session {
    session, err := mgo.Dial(mongosAddr)
    if err != nil {
        loglib.Error(fmt.Sprintf("init mongodb session error:%v", err))
        return nil
    }   

    session.SetMode(mgo.Monotonic, true)    //設置read preference
    session.SetSafe(&mgo.Safe{W:2})         //設置write concern
    return session
}
開發者ID:postfix,項目名稱:logd,代碼行數:11,代碼來源:mongodb_outputer.go

示例12: Start

func (e *etlOutputer) Start() {
	defer func() {
		if err := recover(); err != nil {
			loglib.Error(fmt.Sprintf("etl outputer panic:%v", err))
		}

		e.wq.AllDone()
	}()

	spiderList, _ := e.config["spider_list"]
	colsFile, _ := e.config["columns_file"]
	hostsList, _ := e.config["hosts_white_list"]
	ipBlackList, _ := e.config["ip_black_list"]

	if colsFile != "" {
		e.runEtl(spiderList, colsFile, hostsList, ipBlackList)
	} else {
		loglib.Error("[error] miss columns map file!")
	}
}
開發者ID:postfix,項目名稱:logd,代碼行數:20,代碼來源:etl_outputer.go

示例13: bulkSaveBson

func (this *MongoDbOutputer) bulkSaveBson(coll *mgo.Collection, docs ...interface{}) (err error) {
    if coll != nil {
        err = coll.Insert(docs...)
        if err != nil {
            tmp := make([]string, 0)
            for _, doc := range docs {
                m, _ := doc.(bson.M)
                tid, _ := m[this.transactionIdKey].(string)
                tmp = append(tmp, tid)
            }
            tids := strings.Join(tmp, ",")
            loglib.Error(fmt.Sprintf("save %d bsons [%s] error:%v", len(docs), tids, err))
        }
    }else{
        err = errors.New("bulk: collection is nil")
        loglib.Error(fmt.Sprintf("save bsons error:%v", err))

    }
    return
}
開發者ID:postfix,項目名稱:logd,代碼行數:20,代碼來源:mongodb_outputer.go

示例14: makeDayTag

//touch一個文件表明某一天接收完
func (this *IntegrityChecker) makeDayTag(ip string, day string) bool {
	fname := fmt.Sprintf("%s_%s", ip, day)
	filename := filepath.Join(this.dir, fname)
	fout, err := os.Create(filename)
	if err != nil {
		loglib.Error("tag " + fname + " error: " + err.Error())
		return false
	} else {
		fout.Close()
	}
	return true
}
開發者ID:postfix,項目名稱:logd,代碼行數:13,代碼來源:integrity_checker.go

示例15: GetTotalLines

func (this *Tailler) GetTotalLines(fname string) int {
	cmd := exec.Command("/bin/sh", "-c", `wc -l `+fname+` | awk '{print $1}'`)
	out, err := cmd.Output()
	if err == nil {
		n, err := strconv.Atoi(strings.Trim(string(out), "\n"))
		if err != nil {
			loglib.Error("trans total lines " + string(out) + " error: " + err.Error())
		}
		return n
	}
	return 0
}
開發者ID:postfix,項目名稱:logd,代碼行數:12,代碼來源:tailer.go


注:本文中的logd/loglib.Error函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。