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


Golang log.WriteLog函數代碼示例

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


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

示例1: GetServerState

func GetServerState(address string) int {
	result := common.SERVER_STATE_OFFLINE
	req, err1 := http.NewRequest("GET", address, nil)
	if nil != err1 {
		log.WriteLog("errror %v", err1)
		return result
	}
	httpClient := http.Client{
		Transport: &http.Transport{
			Dial: func(netw, addr string) (net.Conn, error) {
				deadline := time.Now().Add(SERVER_STATE_CHECK_INTERVAL_SEC * time.Second)
				c, err := net.DialTimeout(netw, addr, time.Second*SERVER_STATE_CHECK_INTERVAL_SEC)
				if err != nil {
					return nil, err
				}
				c.SetDeadline(deadline)
				return c, nil
			},
		},
	}

	resp, err := httpClient.Do(req)
	if err != nil {
		log.WriteLog("errror %v", err)
		return result
	}
	// 保證I/O正常關閉
	defer resp.Body.Close()
	// 判斷返回狀態
	if resp.StatusCode == http.StatusOK {
		result = common.SERVER_STATE_ONLINE
	}
	return result
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:34,代碼來源:appTools.go

示例2: SaveSetupInfo

func (setupInfoServiceXmlImpl *setupInfoServiceXmlImpl) SaveSetupInfo(setupInfo interface{}, fileName string, encoding string) error {
	fout, err := os.Create(fileName)
	if nil != err {
		log.WriteLog("error: %v", err)
		return err
	}
	defer fout.Close()
	if nil == setupInfo {
		log.WriteLog("沒有配置對象")
		return err
	}
	output, err := xml.MarshalIndent(setupInfo, "  ", "    ")
	if nil != err {
		log.WriteLog("error: %v\n", err)
		return err
	}
	head := `<?xml version="1.0" `
	if !utils.IsEmptyStr(encoding) {
		head = head + "encoding=\"" + encoding + "\""
	}
	head = head + "?>\n"
	fout.Write([]byte(head))
	if nil != setupInfoServiceXmlImpl.saveXMLContentBefore {
		err = setupInfoServiceXmlImpl.saveXMLContentBefore.saveContentBefore(setupInfo, fout)
		if nil != err {
			return err
		}
	}
	fout.Write(output)
	return nil
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:31,代碼來源:setupInfoServiceXmlImpl.go

示例3: Routes

func (routeUserDelete *RouteUserDelete) Routes(m *martini.ClassicMartini) {
	m.Post("/user/delete", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /user/delete")
		SetResponseJsonHeader(w)
		setupInfo := model.SetupInfo{}
		setupHandle := model.NewSetupHandle()
		if !setupHandle.GetSetupInfo(&setupInfo) {
			return model.GetErrorDtoJson("讀取用戶信息失敗")
		}
		r.ParseForm()
		log.WriteLog("user delete %v", r.Form)
		userName := r.Form.Get("username")

		if common.USER_NAME_ADMIN == userName {
			log.WriteLog("刪除admin失敗")
			return model.GetErrorDtoJson("刪除管理員信息失敗")
		}
		if !setupInfo.DeleteUserByUserName(userName) {
			log.WriteLog("刪除用戶信息失敗")
			return model.GetErrorDtoJson("刪除用戶信息失敗")
		}

		if !setupHandle.SaveSetupInfo(&setupInfo) {
			log.WriteLog("保存刪除用戶信息失敗")
			return model.GetErrorDtoJson("保存刪除用戶信息失敗")
		}
		return model.GetDataDtoJson(nil)
	})
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:29,代碼來源:routeUserDelete.go

示例4: GetSetupInfo

func (setupInfoServiceXmlImpl *setupInfoServiceXmlImpl) GetSetupInfo(setupInfo interface{}, fileName string) error {
	file, err := os.Open(fileName) // For read access.
	if nil != err {
		log.WriteLog("error: %v", err)
		return err
	}
	defer file.Close()
	data, err := ioutil.ReadAll(file)
	if nil != err {
		log.WriteLog("error: %v", err)
		return err
	}
	if nil == setupInfo {
		log.WriteLog("沒有配置對象")
		return err
	}
	decoder := xml.NewDecoder(bytes.NewBuffer(data))
	decoder.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) {
		if charset != common.XML_ENCODE_GB2312 && charset != "GB2312" {
			return input, errors.New("xml: encoding gb2312 is not declared")
		}
		return input, nil
	}

	err = decoder.Decode(setupInfo)
	if nil != err {
		log.WriteLog("error: %v", err)
		return err
	}
	return nil
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:31,代碼來源:setupInfoServiceXmlImpl.go

示例5: GetInfo

func (getListenPortInfoLinux *GetListenPortInfoLinux) GetInfo() ([]int64, error) {
	osErr := getLinuxOSError()
	if nil != osErr {
		return []int64{}, osErr
	}
	bs, err := utils.CmdOutputBytes("ss", "-n", "-l")
	if nil != err {
		return []int64{}, err
	}

	reader := bufio.NewReader(bytes.NewBuffer(bs))

	// ignore the first line
	var line []byte
	line, _, err = reader.ReadLine()
	if err == io.EOF || nil != err {
		return []int64{}, err
	}

	ret := []int64{}

	for {
		line, _, err = reader.ReadLine()
		if err == io.EOF || nil != err {
			break
		}

		arr := strings.Fields(string(line))
		arrlen := len(arr)

		if arrlen != 4 && arrlen != 5 {
			log.WriteLog("output of [ss -n -l] format error")
			continue
		}

		ci := 2
		if arrlen == 5 {
			ci = 3
		}

		location := strings.LastIndex(arr[ci], ":")
		port := arr[ci][location+1:]

		if p, e := strconv.ParseInt(port, 10, 64); e != nil {
			log.WriteLog("parse port to int64 fail: %s", e)
			continue
		} else {
			ret = append(ret, p)
		}

	}

	ret = utils.SliceUniqueInt64(ret)

	return ret, nil
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:56,代碼來源:getListenPortInfoLinux.go

示例6: Routes

func (routeUserSave *RouteUserSave) Routes(m *martini.ClassicMartini) {
	m.Post("/user/save", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /user/save")
		SetResponseJsonHeader(w)
		setupInfo := model.SetupInfo{}
		setupHandle := model.NewSetupHandle()
		if !setupHandle.GetSetupInfo(&setupInfo) {
			return model.GetErrorDtoJson("讀取用戶信息失敗")
		}
		r.ParseForm()
		log.WriteLog("user save %v", r.Form)
		ousername := r.Form.Get("ousername")
		username := r.Form.Get("username")
		addFlag := utils.IsEmptyStr(ousername)
		password := r.Form.Get("password")
		if utils.IsEmptyStr(username) {
			return model.GetErrorDtoJson("沒有用戶名稱")
		}
		if utils.IsEmptyStr(password) {
			return model.GetErrorDtoJson("沒有密碼")
		}
		index := setupInfo.GetUserIndexByUserName(username)
		oindex := setupInfo.GetUserIndexByUserName(ousername)
		var pUserInfo *model.UserInfo = nil
		if addFlag {
			if index > -1 {
				return model.GetErrorDtoJson("用戶名稱輸入重複")
			}
			userInfo := model.UserInfo{UserName: username, Password: password}
			setupInfo.AddUserInfo(userInfo)
			pUserInfo = &userInfo
		} else {
			if oindex < 0 {
				return model.GetErrorDtoJson("沒有找到用戶")
			} else {
				if index > -1 && oindex != index {
					return model.GetErrorDtoJson("用戶名稱輸入重複")
				}
			}
			setupInfo.Users[oindex].UserName = username
			setupInfo.Users[oindex].Password = password
			pUserInfo = &setupInfo.Users[oindex]
		}
		if !setupHandle.SaveSetupInfo(&setupInfo) {
			log.WriteLog("保存刪除用戶信息失敗")
			return model.GetErrorDtoJson("保存刪除用信息失敗")
		}
		return model.GetDataDtoJson(model.UserSaveInfo{UserInfo: *pUserInfo, OUserName: ousername, AddFlag: addFlag})
	})

}
開發者ID:johnnywww,項目名稱:swd,代碼行數:51,代碼來源:routeUserSave.go

示例7: DeleteUserByUserName

func (setupInfo *SetupInfo) DeleteUserByUserName(userName string) bool {
	if nil == setupInfo {
		log.WriteLog("沒有配置對象")
		return false
	}
	index := setupInfo.GetUserIndexByUserName(userName)
	if index < 0 {
		log.WriteLog("通過名稱%s找不到用戶對象", userName)
		return false
	}
	users := setupInfo.Users[0:index]
	setupInfo.Users = append(users, setupInfo.Users[index+1:len(setupInfo.Users)]...)
	return true
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:14,代碼來源:setupInfo.go

示例8: DeleteServerByServerName

func (setupInfo *SetupInfo) DeleteServerByServerName(serverName string) bool {
	if nil == setupInfo {
		log.WriteLog("沒有配置對象")
		return false
	}
	index := setupInfo.GetServerIndexByServerName(serverName)
	if index < 0 {
		log.WriteLog("通過名稱%s找不到服務器對象", serverName)
		return false
	}
	servers := setupInfo.Servers[0:index]
	setupInfo.Servers = append(servers, setupInfo.Servers[index+1:len(setupInfo.Servers)]...)
	return true
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:14,代碼來源:setupInfo.go

示例9: StartHttp

func StartHttp(routeHandle model.RouteHandle) {
	checkEnv()
	port := 9500
	setupInfo := &model.SetupInfo{}
	if model.NewSetupHandle().GetSetupInfo(setupInfo) {
		if setupInfo.Port > 0 {
			port = setupInfo.Port
		}
	}
	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Funcs: []template.FuncMap{{
			"pageStartIndex": getPageStartIndex,
			"pageEndIndex":   getPageEndIndex,
			"pageIndexHtml":  getPageIndexHtml,
			"serverType":     getServerType,
		}},
	}))
	routeHandle.Routes(m)
	error := http.ListenAndServe(":"+strconv.Itoa(port), m)
	if nil != error {
		log.WriteLog("start http %d failed %s", port, error.Error())
	}

}
開發者ID:johnnywww,項目名稱:swd,代碼行數:25,代碼來源:http.go

示例10: Routes

func (routeServerGeneralInfo *RouteServerGeneralInfo) Routes(m *martini.ClassicMartini) {
	m.Get("/server/info/general", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /server/info/general")
		shttp.SetResponseJsonHeader(w)
		result := map[string]string{}
		val, err := service.NewGetSystemTimeInfo().GetInfo()
		if nil != err {
			return model.GetErrorObjDtoJson(err)
		}
		result["time"] = val
		runTimeInfo, err1 := service.NewGetSystemRunTimeInfo().GetInfo()
		if nil != err1 {
			return model.GetErrorObjDtoJson(err1)
		}
		result["runtime"] = fmt.Sprintf("%d天 %d小時 %d分鍾", runTimeInfo.Day, runTimeInfo.Hour, runTimeInfo.Min)
		hostname, err3 := os.Hostname()
		if nil != err3 {
			return model.GetErrorObjDtoJson(err3)
		}
		result["hostname"] = hostname
		ver, err2 := utils.CmdOutputNoLn("uname", "-r")
		if nil != err2 {
			return model.GetErrorObjDtoJson(err2)
		}
		result["kernel"] = ver
		return model.GetDataDtoJson(result)
	})
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:28,代碼來源:routeServerGeneralInfo.go

示例11: getCpuMemRate

func (getAllProcessInfoLinux *GetAllProcessInfoLinux) getCpuMemRate(processInfo *model.ProcessInfo) error {
	bs, err := utils.CmdOutputBytes("ps", "aux")
	if nil != err {
		return err
	}
	reader := bufio.NewReader(bytes.NewBuffer(bs))
	var line []byte
	line, _, err = reader.ReadLine()
	if err == io.EOF || nil != err {
		return errors.New("ps no content")
	}
	var pid int
	for {
		line, _, err = reader.ReadLine()
		if err == io.EOF || nil != err {
			break
		}

		arr := strings.Fields(string(line))
		arrlen := len(arr)

		if arrlen < 7 {
			log.WriteLog("output of [ps aux] format error")
			continue
		}

		pid, err = strconv.Atoi(arr[1])
		if nil != err {
			log.WriteLog("err %v", err)
			continue
		}
		if pid == processInfo.Id {
			processInfo.CPURate, err = strconv.ParseFloat(arr[2], 32)
			if nil != err {
				return err
			}

			processInfo.MemRate, err = strconv.ParseFloat(arr[3], 32)
			if nil != err {
				return err
			}
		}

	}
	return nil
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:46,代碼來源:getAllProcessInfoLinux.go

示例12: GetInfo

func (getAllProcessInfoLinux *GetAllProcessInfoLinux) GetInfo() ([]model.ProcessInfo, error) {
	result := []model.ProcessInfo{}
	dirs, err := utils.GetDirChildDirs("/proc")
	if nil != err {
		return result, err
	}

	// id dir is a number, it should be a pid. but don't trust it
	dirs_len := len(dirs)
	if dirs_len == 0 {
		return result, nil
	}

	var pid int
	for _, pidstr := range dirs {
		if pid, err = strconv.Atoi(pidstr); nil != err {
			err = nil
			continue
		} else {
			p := model.ProcessInfo{Id: pid}

			err = getAllProcessInfoLinux.getCmdLine(&p)
			if nil != err {
				log.WriteLog("read %s fail: %s", fmt.Sprintf("/proc/%d/cmdline", p.Id), err)
				continue
			}
			err = getAllProcessInfoLinux.getProcStatus(&p)
			if nil != err {
				log.WriteLog("read %s fail: %s", fmt.Sprintf("/proc/%d/status", p.Id), err)
				continue
			}
			err = getAllProcessInfoLinux.getCpuMemRate(&p)
			if nil != err {
				log.WriteLog("read mem: %s", err)
				continue
			}
			err = getAllProcessInfoLinux.getRealPath(&p)
			if nil != err {
				continue
			}
			result = append(result, p)
		}
	}

	return result, nil
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:46,代碼來源:getAllProcessInfoLinux.go

示例13: logOut

func logOut(w http.ResponseWriter, r *http.Request, re render.Render) {
	log.WriteLog("addr: /logout")
	userInfo := shttp.GetSessionUserInfo(w, r)
	retInfos := getStrMapRetInfo()
	if nil != userInfo {
		userInfo.Logout()
		retInfos["userName"] = userInfo.UserName
	}
	re.HTML(200, "login", retInfos)
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:10,代碼來源:routeLogout.go

示例14: Exec

func (executeLinuxProcForkChildImpl *executeLinuxProcForkChildImpl) Exec(cmdLine string, dir string) error {
	executeLinuxProc := executeLinuxProcStartProcessImpl{}
	pid, _, errno := syscall.RawSyscall(syscall.SYS_FORK, 0, 0, 0)
	if errno != 0 {
		return syscall.Errno(errno)
	}

	if pid > 0 {
		puid := int(pid)
		processInfo, _ := os.FindProcess(puid)
		if nil != processInfo {
			_, err := processInfo.Wait()
			if nil != err {
				log.WriteLog("Error: find process %s", err.Error())
			}
		}
		return nil
	} else if pid < 0 {
		return errors.New("fork error")
	}

	// pid1, _, errno1 := syscall.RawSyscall(syscall.SYS_FORK, 0, 0, 0)
	// if errno1 != 0 {
	// 	os.Exit(0)
	// 	return errors.New("fork error")
	// }
	// if pid1 > 0 {
	// 	os.Exit(0)
	// 	return nil
	// } else if pid1 < 0 {
	// 	os.Exit(0)
	// 	return errors.New("fork error")
	// }
	_ = syscall.Umask(0)
	_, s_errno := syscall.Setsid()
	if s_errno != nil {
		log.WriteLog("Error: syscall.Setsid errno: %d", s_errno)
	}
	os.Chdir("/")
	result := executeLinuxProc.Exec(cmdLine, dir)
	os.Exit(0)
	return result
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:43,代碼來源:executeLinuxProcForkChildImpl.go

示例15: gotoLoginPage

func gotoLoginPage(w http.ResponseWriter, r *http.Request, re render.Render) {
	userInfo := shttp.GetSessionUserInfo(w, r)
	retInfos := getStrMapRetInfo()
	if nil == userInfo {
		log.WriteLog("not session user name")
	} else {
		retInfos["userName"] = userInfo.UserName
	}
	re.HTML(200, "login", retInfos)
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:10,代碼來源:routeLogin.go


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