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


Golang logger.Error函數代碼示例

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


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

示例1: copyFile

/*複製文件 如果存在則不再複製*/
func copyFile(src, dest string) error {
	srcFile, e := os.Open(src)
	if e != nil {
		logger.Error("copyFile:", e.Error())
		return e
	}
	defer srcFile.Close()

	df, e := os.Open(dest)
	defer df.Close()
	if e != nil && os.IsNotExist(e) {
		logger.Info("desIniFile:", dest, "file not exist!")
		destFile, e := os.Create(dest)
		if e != nil {
			logger.Error("copyFile destFile:", e.Error())
			return e
		}
		defer destFile.Close()
		io.Copy(destFile, srcFile)
		logger.Info("copy file from :", src, " to ", dest)
	} else {
		logger.Info("desIniFile:", dest, "已存在")
	}

	return nil
}
開發者ID:dcmsy,項目名稱:receive,代碼行數:27,代碼來源:receive_file.go

示例2: RunSingleDataPipe

/*執行數據同步讀取直接寫入 single data 單次執行可變的業務數據 */
func (xmlInfo *XmlInfo) RunSingleDataPipe(dbIni *DBini) {
	logger.Info("All run begin >>>>>>>>>>>>>>>>")
	logger.Info("dbIni.F_DbType:", dbIni.F_DbType, "dbIni.T_DbType:", dbIni.T_DbType)
	if !StartFlag {
		return
	}
	defer func() {
		if err := recover(); err != nil {
			logger.Error("查詢數據庫失敗", err)
		}
	}()
	f_pwd, _ := Base64Dec(dbIni.F_Password)
	t_pwd, _ := Base64Dec(dbIni.T_Password)
	dbIni.F_Db.Db_open(dbIni.F_DbType, dbIni.F_User, f_pwd, dbIni.F_Ip, dbIni.F_Port, dbIni.F_Dbname)
	dbIni.T_Db.Db_open(dbIni.T_DbType, dbIni.T_User, t_pwd, dbIni.T_Ip, dbIni.T_Port, dbIni.T_Dbname)
	//關閉數據庫
	defer dbIni.F_Db.db.Close()
	defer dbIni.T_Db.db.Close()

	if dbIni.F_Db.db == nil || dbIni.T_Db.db == nil {
		logger.Error("無法鏈接兩方數據庫")
		panic("無法鏈接兩方數據庫")
		return
	}
	DataSinglePipe(dbIni, xmlInfo)
	Updater(dbIni, xmlInfo)
	ExecProc(dbIni, xmlInfo)
	logger.Info("All run end >>>>>>>>>>>>>>>>")
	time.Sleep(5 * time.Second)
}
開發者ID:dcmsy,項目名稱:receive,代碼行數:31,代碼來源:receive_single_pipe.go

示例3: Check

/*判斷是否需要查詢數據*/
func Check(dbIni *DBini, xmlInfo *XmlInfo) {
	if strings.EqualFold(xmlInfo.IsValData, "true") {
		xmlInfo.CheckFlag = true
		return
	}
	if len(xmlInfo.CheckRowSQL) > 0 {
		defer func() {
			if err := recover(); err != nil {
				logger.Error("查詢數據庫失敗", err)
			}
		}()
		f_pwd, _ := Base64Dec(dbIni.F_Password)
		dbIni.F_Db.Db_open(dbIni.F_DbType, dbIni.F_User, f_pwd, dbIni.F_Ip, dbIni.F_Port, dbIni.F_Dbname)
		defer dbIni.F_Db.db.Close()
		query, err := dbIni.F_Db.db.Query(strings.Replace(xmlInfo.CheckRowSQL, "@[dbname]", dbIni.F_Dbname, -1)) //查詢數據庫
		defer query.Close()

		if err != nil {
			logger.Error("查詢數據庫失敗", err.Error())
			xmlInfo.CheckFlag = false
			panic(err)
			return
		}
		cols, _ := query.Columns()
		values := make([][]byte, len(cols))     //values是每個列的值
		scans := make([]interface{}, len(cols)) //query.Scan的參數 用len(cols)定住當次查詢的長度
		for i := range values {                 //讓每一行數據都填充到[][]byte裏麵
			scans[i] = &values[i]
		}
		dbRows := 0
		if query.Next() {
			//判斷是否與上次的數據一致,如果不一致則查詢數據庫,否則不查詢
			if err := query.Scan(scans...); err != nil { //query.Scan查詢出來的不定長值放到scans[i] = &values[i],也就是每行都放在values裏
				logger.Error(err)
				xmlInfo.CheckFlag = false
				return
			}
			for _, v := range values {
				intV, err := strconv.Atoi(string(v))
				if err != nil {
					xmlInfo.CheckFlag = false
				} else {
					dbRows = intV
				}
			}
			if dbRows != 0 && dbRows != xmlInfo.RowNum { //獲取reader 如何獲取到數據則置為0,如果獲取不到了則賦予全局GobalNum
				xmlInfo.RowNum = dbRows
				xmlInfo.GobalNum = dbRows
				xmlInfo.CheckFlag = true
			} else {
				xmlInfo.CheckFlag = false
			}
		} else {
			xmlInfo.CheckFlag = true
		}
	} else {
		logger.Info(xmlInfo.Remark, "無需查詢係統庫行記錄是否變化")
		xmlInfo.CheckFlag = true
	}
}
開發者ID:dcmsy,項目名稱:datapost,代碼行數:61,代碼來源:datapost_pipe.go

示例4: insertStdOrgMap

/*添加待匹配組織機構*/
func insertStdOrgMap(dbIni *DBini, noneOrgMap map[string]string) {
	stdOrgMapStmt, err := dbIni.T_Db.db.Prepare(StdOrgMapInsertSQL)
	defer stdOrgMapStmt.Close()
	if err != nil {
		logger.Error(err)
		return
	}
	for deptname, _ := range noneOrgMap {
		if len(deptname) == 0 {
			continue
		}
		stdOrgMapQuery, err := dbIni.T_Db.db.Query(StdOrgMapQuerySQL, deptname)
		if err != nil {
			logger.Error("查詢數據庫失敗", err.Error())
			return
		}
		defer stdOrgMapQuery.Close()
		if stdOrgMapQuery.Next() { //如果存在 則判斷是否需要更新 sysnames
			cols, _ := stdOrgMapQuery.Columns()
			colsLength := len(cols)
			values := make([][]byte, colsLength)
			scans := make([]interface{}, colsLength)
			for i := range values {
				scans[i] = &values[i]
			}
			if err := stdOrgMapQuery.Scan(scans...); err != nil {
				logger.Error(err)
				return
			}
			row := make(map[string]string) //每行數據
			for k, v := range values {
				key := cols[k]
				row[key] = string(v)
			}
			id := row["id"]
			sysnames := row["sysnames"]
			if len(sysnames) > 0 && len(dbIni.SysName) > 0 && !strings.Contains(sysnames, dbIni.SysName) {
				updateStmt, err := dbIni.T_Db.db.Prepare(UpdateSQL)
				defer updateStmt.Close()
				if err != nil {
					logger.Error(err)
					return
				}
				updateScans := make([]interface{}, 2)
				updateScans[0] = sysnames + "," + dbIni.SysName
				updateScans[1] = id
				updateStmt.Exec(updateScans...)
			}
		} else { //insert
			stdOrgScans := make([]interface{}, 4)
			stdOrgScans[0] = deptname
			stdOrgScans[1] = dbIni.SysId
			stdOrgScans[2] = dbIni.SysName
			stdOrgScans[3] = dbIni.SysName
			stdOrgMapStmt.Exec(stdOrgScans...)
		}
	}
}
開發者ID:dcmsy,項目名稱:receive,代碼行數:59,代碼來源:receive_orgmatch.go

示例5: StartOrgSync

/*啟動組織機構同步服務*/
func (configinfo *ConfigInfo) StartOrgSync() {
	logger.Info(" StartOrgSync is run... ")
	var orgVersionUrl = "http://" + configinfo.core_ip + ":" + configinfo.core_port + configinfo.orgversion_url
	var allOrgUrl = "http://" + configinfo.core_ip + ":" + configinfo.core_port + configinfo.allorg_url
	logger.Info("orgVersionUrl start >>>>>>>>>>>>>>>>", orgVersionUrl)
	logger.Info("allOrgUrl start >>>>>>>>>>>>>>>>", allOrgUrl)
	//發起鏈接訪問,獲取返回的json數據
	for {
		var return_orgs []byte
		var return_version []byte
		var tmpOrgVersion string = ""
		if response, err := http.Get(orgVersionUrl); err != nil {
			logger.Error(" err = ", err)
		} else {
			defer response.Body.Close()
			if return_version, err = ioutil.ReadAll(response.Body); err != nil {
				logger.Error(" err = ", err)
			}
			tmpOrgVersion = string(return_version)
		}
		logger.Info(" return_version = ", tmpOrgVersion)
		if len(OrgVersion) == 0 || (len(tmpOrgVersion) > 0 && !strings.EqualFold(tmpOrgVersion, OrgVersion)) {
			OrgVersion = tmpOrgVersion
			//重新加載組織機構
			if response, err := http.Get(allOrgUrl); err != nil {
				logger.Error(" err = ", err)
			} else {
				defer response.Body.Close()
				if return_orgs, err = ioutil.ReadAll(response.Body); err != nil {
					logger.Error(" err = ", err)
				}
			}
			var orgInfos []OrgInfo
			err := json.Unmarshal(return_orgs, &orgInfos)
			if err != nil {
				logger.Error(" err = ", err)
			}
			if len(orgInfos) > 0 {
				for k, _ := range OrgMap {
					delete(OrgMap, k)
				}
				for k, _ := range OrgNameMap {
					delete(OrgNameMap, k)
				}
				for i := range orgInfos {
					org := &orgInfos[i]
					OrgMap[org.Org_path] = org.Id
					OrgMap[org.Name] = org.Id
					OrgNameMap[org.Id] = org.Name
				}
			}
		}
		time.Sleep(Time_interval * time.Second)
	}
}
開發者ID:dcmsy,項目名稱:receive,代碼行數:56,代碼來源:receive_orgmatch.go

示例6: InitXmlInfo

/*讀取xml信息初始化xmlinfo*/
func InitXmlInfo(dirName string) XmlInfo {
	content, err := ioutil.ReadFile("xml/HostAudit/repeatetimer_主機審計日誌.xml")
	if err != nil {
		logger.Error(err)
	}
	var result XmlInfo
	err = xml.Unmarshal(content, &result)
	if err != nil {
		logger.Error(err)
	}
	return result
}
開發者ID:dcmsy,項目名稱:datapost,代碼行數:13,代碼來源:datapost_pipe.go

示例7: TestReadXml

/*測試讀取xml*/
func TestReadXml() {
	content, err := ioutil.ReadFile("xml/HostAudit/repeatetimer_主機審計日誌.xml")
	if err != nil {
		logger.Error(err)
	}
	var result XmlInfo
	err = xml.Unmarshal(content, &result)
	if err != nil {
		logger.Error(err)
	}
	logger.Debug(result.FileName)
}
開發者ID:dcmsy,項目名稱:datapost,代碼行數:13,代碼來源:datapost_util.go

示例8: ConServer

func ConServer(hostport string) (*net.TCPConn, error) {
	remoteAddr, err_r := net.ResolveTCPAddr("tcp4", hostport)
	if err_r != nil {
		log.Error("Conn error,ResolveTCPAddr:", hostport)
		return nil, err_r
	}
	conn, err := net.DialTCP("tcp4", nil, remoteAddr)
	if err != nil {
		log.Error("Conn error,connect to", hostport)
		return nil, err
	}

	return conn, nil
}
開發者ID:markman101,項目名稱:Ginger,代碼行數:14,代碼來源:tcpsocket.go

示例9: Db_open

/*獲取數據庫連接 支持mysql mssql mongodb*/
func (f *My_db) Db_open(dbtype string, dbusername string, dbpassowrd string, dbhostsip string, dbport string, dbname string) {
	var connString string
	if strings.EqualFold(dbtype, "mysql") { //root:@tcp(localhost:3306)/go?charset=utf8
		connString = fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8", dbusername, dbpassowrd, dbhostsip, dbport, dbname)
	} else if strings.EqualFold(dbtype, "mssql") {
		connString = fmt.Sprintf("server=%s;user id=%s;password=%s;port=%s;database=%s;encrypt=disable;", dbhostsip, dbusername, dbpassowrd, dbport, dbname)
	}
	Odb, err := sql.Open(dbtype, connString)
	if err != nil {
		logger.Error(err)
		logger.Error("鏈接失敗 >dbusername:%s dbpassowrd:%s dbhostsip:%s dbname:%s", dbusername, dbpassowrd, dbhostsip, dbname)
		f.db = nil
	}
	f.db = Odb
}
開發者ID:dcmsy,項目名稱:datapost,代碼行數:16,代碼來源:datapost_util.go

示例10: Decode_pack

func (protocol *TransProtocolComm) Decode_pack(data []byte) (*Packet, int) {
	log.Info("Enter Decode_pack")
	decodeLen := 0
	pack := &Packet{}
	dataLen := len(data)
	offset := 0
	headLen := binary.Size(pack._header)
	//1.get packhader
	//= not cause out of memory so >= is needed
	for offset = 0; dataLen-offset >= headLen; offset++ {
		pack._header._ver = int16(binary.BigEndian.Uint16(data[offset : offset+2]))
		pack._header._seq = int32(binary.BigEndian.Uint32(data[offset+2 : offset+6]))
		pack._header._type = int16(binary.BigEndian.Uint16(data[offset+6 : offset+8]))
		pack._header._bodyLen = int32(binary.BigEndian.Uint32(data[offset+8 : offset+12]))
		//get pack header successful
		if int16(VER) == pack._header._ver && pack._header._bodyLen < int32(MAX_PACK_SIZE) {
			break
		}
	}
	//2.check is a complete Packet
	if dataLen-offset < headLen || dataLen-offset < int(pack._header._bodyLen) {
		//can't find VER in data Slice or is not a complete pack.
		log.Error("[PACK_NOT_COMPLETE],pack bodyLen is", pack._header._bodyLen)
		return nil, 0
	}

	//3.get a complete pack
	pack._data = make([]byte, pack._header._bodyLen)
	copy(pack._data, data[offset:])
	decodeLen = offset + headLen + int(pack._header._bodyLen)
	return pack, decodeLen
}
開發者ID:markman101,項目名稱:Ginger,代碼行數:32,代碼來源:transprotocol.go

示例11: copyIniFiles

/**複製所有ini文件*/
func copyIniFiles() error {
	var rootName string = "xml_ini"
	var desRootName string = "xml"
	var suffix string = ".ini"
	var rootPath string = "xml_ini//xml_ini.ini"
	var fileFilter string = "/"
	s := []string{rootName, fileFilter}
	var path = strings.Join(s, "")
	results := make(map[string]string)
	err := filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
		if f == nil {
			return err
		}
		if f.IsDir() {
			iniFile := path + fileFilter + f.Name() + suffix
			desIniFile := strings.Replace(path, rootName, desRootName, -1) + fileFilter + f.Name() + suffix
			if !strings.EqualFold(iniFile, rootPath) && strings.HasSuffix(iniFile, suffix) {
				results[desIniFile] = iniFile
				copyFile(iniFile, desIniFile)
			}
		}
		return nil
	})
	if err != nil {
		logger.Error("filepath.Walk() returned %v\n", err)
	}
	return err
}
開發者ID:dcmsy,項目名稱:receive,代碼行數:29,代碼來源:receive_file.go

示例12: log

func log(i int) {
	logger.Debug("Debug>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
	logger.Info("Info>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
	logger.Warn("Warn>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
	logger.Error("Error>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
	logger.Fatal("Fatal>>>>>>>>>>>>>>>>>>>>>>>>>" + strconv.Itoa(i))
}
開發者ID:EastQ,項目名稱:go-logger,代碼行數:7,代碼來源:logger_test.go

示例13: Writer

/*將數據寫入數據庫*/
func Writer(dbIni *DBini, xmlInfo *XmlInfo) {
	logger.Info("***************************")
	logger.Info("Writer begin >>>>>>>>>>>>>>>>")
	if len(xmlInfo.Datas) == 0 {
		logger.Info("Writer end >>>>>>>>>>>>>>>>")
		return
	}
	stmt, err := dbIni.T_Db.db.Prepare(xmlInfo.InsertSQL)
	defer stmt.Close()
	if err != nil {
		logger.Error(err)
		return
	}
	colsLength := len(xmlInfo.Columns)
	c := 0
	arrIds := make([]string, len(xmlInfo.Datas))
	for _, v := range xmlInfo.Datas {
		scans := make([]interface{}, colsLength+2)
		for i := range xmlInfo.Columns {
			scans[i] = v[xmlInfo.Columns[i]]
		}
		scans[colsLength] = dbIni.SysId
		scans[colsLength+1] = dbIni.SysName
		arrIds[c] = v[xmlInfo.Columns[0]]
		stmt.Exec(scans...)
		c++
	}
	xmlInfo.Datas = nil
	xmlInfo.Ids = arrIds
	logger.Info("Writer end >>>>>>>>>>>>>>>>")
}
開發者ID:dcmsy,項目名稱:datapost,代碼行數:32,代碼來源:datapost_pipe.go

示例14: DataLog

/**
 *記錄數據日誌
 *------ flag 1 成功 0 失敗
 *------jobname dataname syscode sysname platform producer beginTime flag endTime errmsg
 */
func DataLog(dbIni *DBini, xmlInfo *XmlInfo, begtime string, err error) {
	stmt, err := dbIni.T_Db.db.Prepare(LogInsertSQL)
	defer stmt.Close()
	if err != nil {
		logger.Error(err)
		return
	}
	scans := make([]interface{}, 10)
	var flag string = "1"
	var msg string
	if err != nil {
		flag = "0"
		msg = string(err.Error())
	}
	scans[0] = xmlInfo.Remark
	scans[1] = xmlInfo.Remark
	scans[2] = dbIni.SysId
	scans[3] = dbIni.SysName
	scans[4] = dbIni.Platform
	scans[5] = dbIni.Company
	scans[6] = begtime
	scans[7] = flag
	scans[8] = NowTime()
	scans[9] = msg
	stmt.Exec(scans...)
}
開發者ID:dcmsy,項目名稱:receive,代碼行數:31,代碼來源:receive_log.go

示例15: StdOrgSync

/*已匹配組織機構信息*/
func (sys *SysIni) StdOrgSync() {
	logger.Info("StdOrgSync start >>>>>>>>>>>>>>>>")
	defer func() {
		if err := recover(); err != nil {
			logger.Error("查詢數據庫失敗", err)
		}
	}()
	for {
		dbIni := &sys.dbini
		t_pwd, _ := Base64Dec(dbIni.T_Password)
		dbIni.T_Db.Db_open(dbIni.T_DbType, dbIni.T_User, t_pwd, dbIni.T_Ip, dbIni.T_Port, dbIni.T_Dbname)
		defer dbIni.T_Db.db.Close()
		query, err := dbIni.T_Db.db.Query(MapQuerySQL) //查詢數據庫
		if err != nil {
			logger.Error("查詢數據庫失敗", err.Error())
			panic(err)
			return
		}
		defer query.Close()
		for k, _ := range StdOrgMap {
			delete(StdOrgMap, k)
		}

		cols, _ := query.Columns()
		colsLength := len(cols)
		values := make([][]byte, colsLength)
		scans := make([]interface{}, colsLength)
		for i := range values {
			scans[i] = &values[i]
		}
		for query.Next() { //循環
			if err := query.Scan(scans...); err != nil {
				logger.Error(err)
				return
			}
			row := make(map[string]string) //每行數據
			for k, v := range values {
				key := cols[k]
				row[key] = string(v)
			}
			StdOrgMap[row["map_deptname"]] = row["std_deptid"]
		}
		time.Sleep(Time_interval * time.Second)
	}
}
開發者ID:dcmsy,項目名稱:receive,代碼行數:46,代碼來源:receive_orgmatch.go


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