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


Golang logs.Log函數代碼示例

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


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

示例1: FetchTaskList

//獲取所有任務的任務列表
func FetchTaskList() (int, *list.List) {
	var stmtIns *sql.Stmt
	var err error
	stmtIns, err = db.Prepare("select task_id, create_time from rdb_parse_task")

	if err != nil {
		logs.Log("fetch task list error in dbutil db.Prepare : " + err.Error())
		return -1, list.New()
	}

	defer stmtIns.Close()

	rows, errs := stmtIns.Query()

	if errs != nil {
		logs.Log("fetch task list error in dbutil stmtIns.Query : " + errs.Error())
		return -2, list.New()
	}

	taskList := list.New()

	var taskId string
	var createTime string
	for rows.Next() {
		var task Task
		rows.Scan(&taskId, &createTime)
		task.TaskId = taskId
		task.CreateTime = createTime
		taskList.PushBack(task)
	}
	return 1, taskList
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:33,代碼來源:dbutil.go

示例2: FetchResult

//根據taskId和type獲取分析結果
func FetchResult(taskId string, types string, limit int, offset int) []string {
	result := make([]string, 0)
	stmtIns, err := db.Prepare("select content from rdb_anly_result where task_id = ? and type = ? order by id desc limit ? offset ? ")

	if err != nil {
		logs.Log("fetch result error in dbutil db.Prepare!" + " : " + err.Error())
		return result
	}

	defer stmtIns.Close()

	rows, errs := stmtIns.Query(taskId, types, limit, offset)
	if errs != nil {
		logs.Log("fetch result error in dbutil stmtIns.Query!" + " : " + errs.Error())
		return result
	}

	var content string

	for rows.Next() {
		rows.Scan(&content)
		result = append(result, content)
	}
	return result
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:26,代碼來源:dbutil.go

示例3: DeleteTask

//刪除任務,以及任務的分析結果
func DeleteTask(list *list.List) bool {

	stmtInsTask, err := db.Prepare("delete from rdb_parse_task where task_id = ?")

	if err != nil {
		logs.Log("delete task stmtInsTask error in dbutil : " + err.Error())
		return false
	}

	defer stmtInsTask.Close()

	stmtResult, err := db.Prepare("delete from rdb_anly_result where task_id = ?")
	if err != nil {
		logs.Log("delete dask stmtResult error in dbutil : " + err.Error())
		return false
	}

	defer stmtResult.Close()

	for e := list.Front(); e != nil; e = e.Next() {
		taskId, ok := e.Value.(string)
		if ok {
			stmtInsTask.Exec(taskId)
			stmtResult.Exec(taskId)
		} else {
			logs.Log("type error!")
		}
	}
	return true
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:31,代碼來源:dbutil.go

示例4: pipelineAnalyze

//管道讀取
func pipelineAnalyze(inputFile string, param *Parameters) {
	file, err := os.Open(inputFile)

	if err != nil && err != io.EOF {
		logs.Log("file open error in parseRdb pipelineAnalyze : " + err.Error())
		return
	}

	defer file.Close()

	//首先讀取一定數量的字節
	buff := make([]byte, (*param).SliceContent)

	n, err := file.Read(buff)
	if err != nil && err != io.EOF {
		logs.Log("file read error in parseRdb pipelineAnalyze : " + err.Error())
		return
	}

	//解析
	var pbuff = &buff
	if n != 0 {
		(*param).OffsetBytes = (*param).OffsetBytes + int64(n)
		parseRedisRdb(pbuff, inputFile, param)
		(*param).FixedInfo = true
	}
	//為了防止文件沒有全部讀取,再次循環讀取,理論上這個地方應該用不到
	for {
		n, err := file.ReadAt(buff, (*param).OffsetBytes)

		if err != nil && err != io.EOF {
			logs.Log("file read error in parseRdb pipelineAnalyze for loop : " + err.Error())
			return
		}

		defer file.Close()

		if n == 0 {
			break
		} else {
			(*param).SliceStart = 0
			(*param).SliceEnd = (*param).SliceStart + 1
			(*param).OffsetBytes = (*param).OffsetBytes + int64(n)
			parseRedisRdb(pbuff, inputFile, param)
			(*param).FixedInfo = true
		}
	}
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:49,代碼來源:parseRdb.go

示例5: Start

/**
這個是解析的入口
pwflag 表示是打印還是寫入到文件
0 打印
1 寫入到文件
2 寫入到數據庫
filename 表示要解析的文件路徑
*/
func Start(inputFile string, filterLength int, filterKey string) Parameters {

	//讀取管道的大小
	conf := config.SetConfig("important.properties")
	sliceContent, _ := strconv.ParseUint(conf.GetValue("pipeline", "size"), 10, 64)
	if sliceContent < 16 {
		sliceContent = 16
		logs.Log("sliceContent < 16")
	}

	var heapIni bool = false

	var param Parameters
	param.Success = false
	param.SliceStart = 0
	param.SliceEnd = 0
	param.Step = []uint64{5, 4}
	param.FileFlag = false
	param.SliceContent = sliceContent
	param.FixedInfo = false
	param.OffsetBytes = 0
	param.Dbnum = -1
	param.ResultMap = make(map[string]int)
	param.ValueFilterLength = filterLength
	param.FilterKey = filterKey
	param.ValueLengthFilterList = list.New()
	param.KeyFilterMap = make(map[string]int)
	param.Heap = &sorting.Heap{}
	param.HeapInit = &heapIni
	pipelineAnalyze(inputFile, &param)

	return param
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:41,代碼來源:parseRdb.go

示例6: UpdateTaskStatus

//更新任務狀態
func UpdateTaskStatus(status int, taskId string) bool {
	stmtIns, err := db.Prepare("update rdb_parse_task set status = ? where task_id = ?")

	if err != nil {
		logs.Log("update task status error in dbutil db.Prepare : " + err.Error())
		return false
	}
	defer stmtIns.Close()

	_, errs := stmtIns.Exec(status, taskId)
	if errs != nil {
		logs.Log("update task status error in dbutil stmtIns.Exec : " + errs.Error())
		return false
	}
	return true
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:17,代碼來源:dbutil.go

示例7: Store

//存儲分析結果
func Store(content, types, taskId string) {

	stmtIns, err := db.Prepare("insert into rdb_anly_result(content, type, task_id, create_time) values (?,?,?,now())")

	if err != nil {
		logs.Log("store error in dbutil db.Prepare : " + err.Error())
		return
	}
	defer stmtIns.Close()

	_, errs := stmtIns.Exec(content, types, taskId)

	if errs != nil {
		logs.Log("store error in dbutil stmtIns.Exec : " + errs.Error())
		return
	}
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:18,代碼來源:dbutil.go

示例8: InsertTask

//向任務表中插入任務
func InsertTask(host, port, taskId string, filterLength, priority int, filter_key string) bool {

	stmtIns, err := db.Prepare("insert into rdb_parse_task (host, port, filter_length, filter_key, task_id, priority, status, create_time) values (?,?,?,?,?,?,0,now())")

	if err != nil {
		logs.Log("insert task error in dbutil db.Prepare : " + err.Error())
		return false
	}
	defer stmtIns.Close()

	_, errs := stmtIns.Exec(host, port, filterLength, filter_key, taskId, priority)
	if errs != nil {
		logs.Log("insert task error in dbutil stmtIns.Exec : " + errs.Error())
		return false
	}
	return true
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:18,代碼來源:dbutil.go

示例9: parseTask

//解析程序
func parseTask(host string, port string, filterLength int, filterKey string, taskId string) {

	//獲得機器的ip地址
	ip := utils.GetIpAddress()
	if ip == "unknown" {
		ip = utils.GetIpAddress2()
	}
	logs.Log("machine : " + ip + " processing task : " + taskId)
	//獲取rdb文件
	rdbFile := rdbLocation + taskId + ".rdb"

	//如果文件存在則刪除
	isExist := exists(rdbFile)
	if isExist == true {
		err := os.Remove(rdbFile)
		if err != nil {
			logs.Log("parseTask remove rdbFile error : " + err.Error())
			return
		}
	}

	flag := syncRdb(host, port, cliLocation, rdbFile, taskId)
	if flag == 1 {
		//還要判斷解析是否成功了
		status := start(rdbFile, taskId, filterLength, filterKey)
		if status == true {
			dbutil.UpdateTaskStatus(1, taskId)
		} else {
			dbutil.UpdateTaskStatus(3, taskId)
		}
		//刪除文件
		dropFile(rdbFile, taskId)
	} else {
		switch flag {
		case 2: //同步進程失效,文件大小無變化
			logs.Log("task " + taskId + " sync process error, file size no change!")
			dbutil.UpdateTaskStatus(2, taskId)
		case 4: //獲得redis密碼錯誤
			dbutil.UpdateTaskStatus(4, taskId)
			logs.Log("task " + taskId + " get remote redis server login password error!")
		}
		//刪除文件
		dropFile(rdbFile, taskId)
	}
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:46,代碼來源:main.go

示例10: GetIpAddress

/**
net 環境下能夠獲得訪問網絡的ip
*/
func GetIpAddress() string {
	conn, err := net.Dial("udp", "www.baidu.com:80")
	if err != nil {
		logs.Log(err.Error())
		return "unknown"
	}
	defer conn.Close()
	return strings.Split(conn.LocalAddr().String(), ":")[0]
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:12,代碼來源:utils.go

示例11: dropFile

//解析操作完成之後刪除文件
func dropFile(file, taskId string) {
	//首先判斷存在文件嗎
	isExist := exists(file)
	if isExist {
		err := os.Remove(file)
		if err != nil {
			logs.Log("task " + taskId + " remove file error : " + err.Error() + " --- " + file)
		}
	}
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:11,代碼來源:main.go

示例12: FetchTaskById

//根據任務id獲取單個任務
func FetchTaskById(task_id string) (int, *list.List) {
	stmtIns, err := db.Prepare("select host, port, filter_length, filter_key, task_id, priority, status, create_time from rdb_parse_task where task_id = ?")

	if err != nil {
		logs.Log("fetch task by id error in dbutil db.Prepare : " + err.Error())
		return -1, list.New()
	}

	defer stmtIns.Close()

	rows, errs := stmtIns.Query(task_id)

	if errs != nil {
		logs.Log("fetch task by id error in dbutil stmtIns.Query : " + errs.Error())
		return -2, list.New()
	}

	taskList := list.New()

	var host string
	var port string
	var filterLength int
	var filterKey string
	var taskId string
	var priority int
	var status int
	var createTime string
	for rows.Next() {
		var task Task
		rows.Scan(&host, &port, &filterLength, &filterKey, &taskId, &priority, &status, &createTime)
		task.Host = host
		task.Port = port
		task.FilterLength = filterLength
		task.TaskId = taskId
		task.Priority = priority
		task.Status = status
		task.CreateTime = createTime
		task.FilterKey = filterKey
		taskList.PushBack(task)
	}
	return 1, taskList
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:43,代碼來源:dbutil.go

示例13: StoreSortingResult

//存儲堆排序結果
func StoreSortingResult(h *sorting.Heap, taskId string) {
	for h.Len() > 0 {
		element := heap.Pop(h).(sorting.Element)
		b, err := json.Marshal(element)
		if err != nil {
			logs.Log("json marshal error in StoreValueTypeStat : " + err.Error())
			return
		}
		dbutil.Store(string(b), "2", taskId)
	}
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:12,代碼來源:analysis.go

示例14: startParse

//為了部署多個實例的需要,修改了startParse
func startParse() {

	//每次隻取一個任務,這樣保證當存在多個服務時,每個機器都能獲得任務
	logs.Log("starting parse!")
	for {
		mark, task := dbutil.FetchNewTask()

		if mark == 1 {
			if task.TaskId == "" {
				time.Sleep(time.Second * 10)
				continue
			} else {
				parseTask(task.Host, task.Port, task.FilterLength, task.FilterKey, task.TaskId)
			}
		} else if mark == -5 {
			logs.Log("task " + task.TaskId + " processing by another machine! ")
		} else {
			logs.Log("fetch task error!")
		}
	}
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:22,代碼來源:main.go

示例15: StoreValueLengthFilter

func StoreValueLengthFilter(list *list.List, fileId string) {

	for e := list.Front(); e != nil; e = e.Next() {
		str, ok := e.Value.(string)
		if ok {
			dbutil.Store(str, "2", fileId)
		} else {
			logs.Log("list element error in StoreValueLengthFilter list element is not string!")
			continue
		}
	}
}
開發者ID:z383966992,項目名稱:redis-rdb-parse,代碼行數:12,代碼來源:analysis.go


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