当前位置: 首页>>代码示例>>Golang>>正文


Golang log.Error函数代码示例

本文整理汇总了Golang中gostore/log.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Save

func (lfh *LocalFileHeader) Save() {
	// TODO: Fix this double marshalling!

	bytes, err := json.Marshal(lfh.header)

	if err != nil {
		log.Error("Couldn't marshal header: %s", err)
	}

	file, err := os.Create(lfh.headerpath)
	if err != nil {
		log.Error("Couldn't save header file for %s: %s", lfh.headerpath, err)

	} else {
		n, err := file.Write(lfh.header.ToJSON())

		if n != len(bytes) {
			log.Error("Didn't write all header data: written %n bytes", n)
		}

		if err != nil {
			log.Error("Couldn't save file header: %s", err)
		}
	}

	file.Close()
}
开发者ID:appaquet,项目名称:gostore,代码行数:27,代码来源:header.go

示例2: replicationWatcher

func (fss *FsService) replicationWatcher() {
	for fss.running {
		if fss.replQueue.Len() > 0 {
			fss.replQueueMutex.Lock()
			if fss.replQueue.Len() > 0 {
				next := fss.replQueue.Front()
				fss.replQueue.Remove(next)
				fss.replQueueMutex.Unlock()

				path := next.Value.(*Path)
				localheader := fss.headers.GetFileHeader(path)

				log.Info("%d: FSS: Starting replica download for path %s version %d...", fss.cluster.MyNode.Id, path, localheader.header.Version)

				// TODO: Make sure we don't download the same replica twice...

				// check if the file doesn't already exist locally
				file := OpenFile(fss, localheader, 0)
				if !file.Exists() {
					// TODO: Use config to get temp path
					tempfile := fmt.Sprintf("%s/%d.%d.%d.data", os.TempDir(), path.Hash(), time.Nanoseconds(), localheader.header.Version)

					fd, err := os.Create(tempfile)
					if err == nil {
						_, err = fss.Read(path, 0, -1, 0, fd, nil)
						fd.Close()
						if err == nil {
							os.Rename(tempfile, file.datapath)
							log.Info("%d: FSS: Successfully replicated %s version %d locally", fss.cluster.MyNode.Id, path, localheader.header.Version)

						} else {
							log.Error("%d: FSS: Couldn't replicate file %s locally because couldn't read: %s", fss.cluster.MyNode.Id, path, err)
						}

					} else {
						log.Error("%d: FSS: Couldn't open temporary file %s to download replica localy for path %s", fss.cluster.MyNode.Id, tempfile, path)
						os.Remove(tempfile)
					}

				} else {
					log.Info("%d: FSS: Local replica for %s version %d already exist", fss.cluster.MyNode.Id, path, localheader.header.Version)
				}

			} else {
				fss.replQueueMutex.Unlock()
			}

		} else {
			// if no more replica in the queue, stop replica force
			if fss.replQueue.Len() == 0 {
				fss.replForce = false
			}
		}

		// TODO: Put that in configuration
		if !fss.replForce {
			time.Sleep(100 * 1000 * 1000)
		}
	}
}
开发者ID:appaquet,项目名称:gostore,代码行数:60,代码来源:service_replication.go

示例3: acceptUDP

func (s *Server) acceptUDP() {
	// Looping for new messages
	for {
		buf := make([]byte, MAX_MSG_SIZE)
		n, adr, err := s.udpsock.ReadFrom(buf)

		if s.comm.running {
			if err != nil {
				log.Error("Error while reading UDP (read %d) from %s: %s\n", n, adr, err)

			} else {
				abcon := net.Conn(s.udpsock)
				connection := NewConnection(s.comm.pool, P_UDP, D_Inbound, abcon)
				read := io.Reader(bytes.NewBuffer(buf))
				msg := s.comm.NewMessage()
				msg.connection = connection
				err := msg.readMessage(read)

				if err != nil {
					log.Error("Couldn't handle message received from UDP because of errors: %s %s\n", msg, err)
				} else {
					go s.comm.handleMessage(msg)
				}
			}
		} else {
			log.Info("Dropping connection because communications have been paused")
		}
	}
}
开发者ID:appaquet,项目名称:gostore,代码行数:29,代码来源:server.go

示例4: sendToReplicaNode

func (fss *FsService) sendToReplicaNode(resolv *cluster.ResolveResult, req_cb func(node *cluster.Node) *comm.Message) chan os.Error {
	toSyncCount := resolv.Count() - 1 // minus one for the master
	var syncError os.Error = nil
	myNodeId := fss.cluster.MyNode.Id
	errChan := make(chan os.Error, 1) // channel used to return data to the messageor
	c := make(chan bool, toSyncCount) // channel used to wait for all replicas

	if toSyncCount > 0 {
		go func() {
			for i := 0; i < resolv.Count(); i++ {
				node := resolv.Get(i)

				if node.Status == cluster.Status_Online && node.Id != myNodeId {
					// get the new message
					req := req_cb(node)

					req.Timeout = 1000 // TODO: Config
					req.OnResponse = func(message *comm.Message) {
						log.Debug("%d: FSS: Received acknowledge message for message %s\n", fss.cluster.MyNode.Id, req)
						c <- true
					}
					req.OnTimeout = func(last bool) (retry bool, handled bool) {
						// TODO: Retry it!
						syncError = comm.ErrorTimeout
						log.Error("%d: FSS: Couldn't send message to replicate node %s because of a timeout for message %s\n", fss.cluster.MyNode.Id, node, req)
						c <- true

						return true, false
					}
					req.OnError = func(message *comm.Message, syncError os.Error) {
						log.Error("%d: FSS: Received an error while sending to replica %s for message %s: %d %s\n", fss.cluster.MyNode.Id, req, node, syncError)
						c <- true
					}

					fss.comm.SendNode(node, req)
				}
			}

			// wait for nodes to sync the handoff
			for i := 0; i < toSyncCount; i++ {
				<-c
			}

			errChan <- syncError
		}()
	} else {
		errChan <- nil
	}

	return errChan
}
开发者ID:appaquet,项目名称:gostore,代码行数:51,代码来源:service_replication.go

示例5: Save

func (c Config) Save(path string) {
	bytes, err := json.Marshal(c)

	if err != nil {
		log.Error("Couldn't save config: %s", err)
	}

	fc, err := os.Create(path)
	_, err = fc.Write(bytes)

	if err != nil {
		log.Error("Couldn't write config: %s", err)
	}
}
开发者ID:appaquet,项目名称:gostore,代码行数:14,代码来源:config.go

示例6: LoadConfig

func LoadConfig(path string) Config {
	config := new(Config)

	fc, err := os.Open(path)
	if err != nil {
		log.Error("Couldn't load config file: %s", err)
	}

	buf := new(bytes.Buffer)
	buf.ReadFrom(fc)

	strOrigConfig := string(buf.Bytes())
	strFinConfig := ""
	lines := strings.Split(strOrigConfig, "\n", -1)
	for _, line := range lines {
		trimedLine := strings.TrimSpace(line)
		if len(trimedLine) < 2 || trimedLine[:2] != "//" {
			strFinConfig += trimedLine
		}
	}

	err = json.Unmarshal([]byte(strFinConfig), config)

	if err != nil {
		log.Fatal("Couldn't unmarshal config: %s %s", strFinConfig, err)
	}

	return *config
}
开发者ID:appaquet,项目名称:gostore,代码行数:29,代码来源:config.go

示例7: RemoteContactMaster

func (cs *ClusterService) RemoteContactMaster(msg *comm.Message) {
	myNode := cs.cluster.MyNode
	log.Debug("%d: Got a ContactMaster request: %s", myNode.Id, msg)

	if cs.state == state_online {
		masters := cs.cluster.Rings.GetRing(cs.masterRing).ResolveToken(master_token)

		// make sure I'm the master, and online
		if myNode.Status == cluster.Status_Online && masters.IsFirst(myNode) {
			node := cluster.NewEmptyNode()
			err := node.Unserialize(msg.Message)
			if err != nil {
				cs.comm.RespondError(msg, os.NewError("Couldn't unmarshal node data"))
				log.Error("Couldn't unmarshal node data: %s", err)
				return
			}

			node.Status = cluster.Status_Online
			cs.cluster.MergeNode(node, true)

			// TODO: Send the cluster back to the node
			resp := cs.comm.NewMsgMessage(cs.serviceId)
			cs.comm.RespondSource(msg, resp)
			//log.Fatal("BLABLA", node.Id)

			// TODO: LOCK SO THAT WE DON'T MAKE IT ONLINE TWICE

			// TODO: Accept the node
			// TODO: Check its rings
			// TODO: Broadcast the change
		} else {
			cs.comm.RedirectFirst(masters, msg)
		}
	}
}
开发者ID:appaquet,项目名称:gostore,代码行数:35,代码来源:service.go

示例8: replay

func (s *segment) replay(db *Db) (err os.Error) {
	log.Info("Replaying segment %s", s)

	entrych, errch := s.iter(0)

	end := false
	count := 0
	for !end {
		select {
		case entry, ok := <-entrych:
			if ok {
				count++
				err = entry.mutation.execute(db, true) // execute mutation (for replay)
				if err != nil {
					log.Error("Got an error replaying a mutation: %s", err)
					return
				}
			} else {
				end = true
			}

		case segerr, ok := <-errch:
			if ok {
				return segerr
			} else {
				end = true
			}
		}
	}

	log.Info("Segment %s replayed: %d mutations replayed", s, count)

	return
}
开发者ID:appaquet,项目名称:gostore,代码行数:34,代码来源:segment.go

示例9: ToJSON

func (f *FileHeader) ToJSON() []byte {
	bytes, err := json.Marshal(f)
	if err != nil {
		log.Error("Couldn't marshal header: %s", err)
	}

	return bytes
}
开发者ID:appaquet,项目名称:gostore,代码行数:8,代码来源:header.go

示例10: Unlock

func (fss *FsService) Unlock(key string) {
	mutex, found := fss.mutexes[key]
	if !found {
		log.Error("FSS: Couldn't find file mutex to unlock for key %s\n", key)
		return
	}

	mutex.Unlock()
}
开发者ID:appaquet,项目名称:gostore,代码行数:9,代码来源:service.go

示例11: Size

func (f *File) Size() int64 {
	dir, err := os.Stat(f.datapath)
	if err != nil {
		log.Error("Cannot stat data file: %s\n", f.path)
	} else {
		return dir.Size
	}

	return 0
}
开发者ID:appaquet,项目名称:gostore,代码行数:10,代码来源:file.go

示例12: NewServer

// Returns an API Server
func NewServer(handler Handler, adr string) *Server {
	server := new(Server)
	server.handler = handler
	server.servmux = http.NewServeMux()

	con, err := net.Listen("tcp", adr)
	if err != nil {
		log.Error("API: Couldn't create listener socket: %s\n", err)
	}

	// Add handling function at root, delegating everything to the handler
	server.servmux.HandleFunc("/", func(httpresp http.ResponseWriter, httpreq *http.Request) {
		log.Debug("API: Connection on url %s\n", httpreq.URL)

		resp := &ResponseWriter{httpresp}

		var req *Request
		if req = NewRequest(resp, httpreq); req == nil {
			log.Error("API: Couldn't create request object")
			return
		}

		handler.Handle(resp, req)

		// TODO: Remove that! Shouldn't be here!!
		// Read the rest, so we don't cause Broken Pipe on the other end if we don't read to the end
		ioutil.ReadAll(req.Body)
	})

	// Start serving the API on another thread
	go func() {
		log.Debug("API: Starting API server on adr %s\n", adr)
		err = http.Serve(con, server.servmux)
		con.Close()

		if err != nil {
			log.Fatal("API: Serve error: ", err.String())
		}
	}()

	return server
}
开发者ID:appaquet,项目名称:gostore,代码行数:43,代码来源:server.go

示例13: ReturnJSON

// Returns an interface marshaled in JSON
func (r *ResponseWriter) ReturnJSON(v interface{}) {

	bytes, err := json.Marshal(v)
	if err != nil {
		log.Error("API: Couldn't marshall JSON response: %s\n", err)
	}

	r.Header().Set("Content-Type", "application/json")
	//r.SetHeader("Content-Type", "application/json")
	r.Write(bytes)
}
开发者ID:appaquet,项目名称:gostore,代码行数:12,代码来源:response.go

示例14: LoadFileHeaderFromJSON

func LoadFileHeaderFromJSON(bytes []byte) *FileHeader {
	fh := new(FileHeader)
	errtok := json.Unmarshal(bytes, fh)

	if errtok != nil {
		fh = new(FileHeader)
		log.Error("Couldn't load file header: %s, %s", errtok, bytes)
	}

	return fh
}
开发者ID:appaquet,项目名称:gostore,代码行数:11,代码来源:header.go

示例15: get

func (api *api) get(resp *rest.ResponseWriter, req *rest.Request, path *Path) {
	log.Debug("FSS API: Received a read request for path %s\n", path)

	// TODO: Handle offset
	// TODO: Handle version
	// TODO: Handle size
	_, err := api.fss.Read(path, 0, -1, 0, resp, nil)
	log.Debug("API: Fs Read data returned\n")
	if err != nil && err != os.EOF {
		log.Error("API: Fs Read returned an error for %s: %s\n", path, err)
		resp.ReturnError(err.String())
	}
}
开发者ID:appaquet,项目名称:gostore,代码行数:13,代码来源:api.go


注:本文中的gostore/log.Error函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。