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


Golang log.Println函数代码示例

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


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

示例1: runDelayedChecks

// Using Panamax data, loop through the checks that are delayed, executing them
// sequentially. This method is intended to run in background.
func (g *GoDutch) runDelayedChecks() {
	var name string
	var lastRun int64
	var req *Request
	var err error

	if g.lastRunThreshold <= 0 {
		log.Println("[GoDutch] lastRunThreshold is disabled, no auto-run.")
		return
	}

	log.Printf("[GoDutch] Checks will run automatically after: %ds",
		g.lastRunThreshold)

	for {
		time.Sleep(10 * time.Second)
		log.Println("[GoDutch] Sleep done, looking for delayed checks.")

		for name, lastRun = range g.p.ChecksRunReport(g.lastRunThreshold) {
			log.Printf("[GoDutch] Executing '%s', last run at %ds ago (%ds threshold)",
				name, lastRun, g.lastRunThreshold)
			if req, err = NewRequest(name, []string{}); err != nil {
				log.Fatalln("[GoDutch] Error on creating request to: '%s'", name)
			}
			if _, err = g.p.Execute(req); err != nil {
				log.Println("[GoDutch] Error on execute: ", err)
			}
		}
	}
}
开发者ID:otaviof,项目名称:godutch,代码行数:32,代码来源:godutch.go

示例2: Run

// Run runs the the tunnel session
func (s *Session) Run() (err error) {
	defer s.recoverPanic("Session.Run")

	go func() {
		defer s.recoverPanic("Session.mux.Wait")
		code, err, debug1 := s.mux.Wait()
		//		s.Info("Session mux shutdown with code %v error %v debug %v", code, err, debug)
		log.Println(fmt.Sprintf("[INFO] Session mux shutdown with code %v error %v debug %v", code, err, debug1))
	}()

	defer s.mux.Close()

	// A tunnel session starts with an auth stream
	if err = s.handleAuth(); err != nil {
		return
	}

	// then we handle new streams sent from the client
	for {
		stream, err := s.mux.Accept()
		if err != nil {
			s.Shutdown()
			err := fmt.Errorf(fmt.Sprintf("Failed to accept stream: %v", err))
			log.Println(fmt.Sprintf("[ERROR] %v", err))
			return err
		}

		go s.handleStream(conn.Wrap(stream, "stream", s.id))
	}
}
开发者ID:shenshouer,项目名称:go-tunnel,代码行数:31,代码来源:session.go

示例3: DefaultHandler

func DefaultHandler(w http.ResponseWriter, r *http.Request) {
	log.Println("Serving index.html to ", r.RemoteAddr)

	tmpl, err := template.ParseFiles("templates/index.html")
	if err != nil {
		Write404(w, r)
		log.Println("error loading index.html!")
		return
	}

	if client, ok := clientList[r.RemoteAddr]; ok {
		client.LastUpdate = time.Now()
		clientList[r.RemoteAddr] = client
	} else {
		mutex.Lock()
		client := clientInfo{
			NodeID:     "SC-0.1-" + strconv.Itoa(GNodeID),
			Address:    net.ParseIP(r.RemoteAddr),
			LastUpdate: time.Now(),
		}
		GNodeID++
		mutex.Unlock()

		clientList[r.RemoteAddr] = client
	}

	tmpl.Execute(w, struct {
		NodeID   string
		NumNodes int
	}{clientList[r.RemoteAddr].NodeID, len(clientList)})
}
开发者ID:gearmover,项目名称:myownsupercomputer,代码行数:31,代码来源:main.go

示例4: CopyFileFromPeer

func (tnt *TnTServer) CopyFileFromPeer(srv int, path string, dest string) error {
	/*
	  (1) Call 'GetFile' RPC on server 'srv'
	  (2) Write the file preserving permissions
	*/

	args := &GetFileArgs{FilePath: path}
	var reply GetFileReply

	ok := call(tnt.servers[srv], "TnTServer.GetFile", args, &reply)
	if ok {
		if reply.Err != nil {
			log.Println("CopyFileFromPeer:", tnt.me, ": Error opening file:", reply.Err)
		} else {
			err := ioutil.WriteFile(tnt.root+dest, reply.Content, reply.Perm)
			if err != nil {
				log.Println("CopyFileFromPeer:", tnt.me, ": Error writing file:", err)
			}
		}
	} else {
		log.Println(tnt.me, ": GetFile RPC failed")
	}

	return reply.Err
}
开发者ID:jnhnum1,项目名称:fss,代码行数:25,代码来源:server.go

示例5: monitorFlume

func (self *SourceManager) monitorFlume() {
	for self.isRunning {
		time.Sleep(1 * time.Second)
		monitor := "FLUME_TPS|"
		for k, v := range self.sourceServers {

			succ, fail := v.monitor()
			monitor += fmt.Sprintf("%s|%d/%d \t", k, succ, fail)
		}
		log.Println(monitor)

		mk := make([]string, 0)
		monitor = "FLUME_POOL|\n"
		for k, _ := range self.hp2flumeClientPool {
			mk = append(mk, k.Host+":"+strconv.Itoa(k.Port))
		}
		sort.Strings(mk)

		for _, hp := range mk {
			v, ok := self.hp2flumeClientPool[config.NewHostPort(hp)]
			if !ok {
				continue
			}
			active, core, max := v.FlumePool.MonitorPool()
			monitor += fmt.Sprintf("%s|%d/%d/%d\n", hp, active, core, max)
		}

		log.Println(monitor)
	}
}
开发者ID:rejoicelee,项目名称:flume-log-sdk,代码行数:30,代码来源:log_source_manager.go

示例6: connectToDiscord

func connectToDiscord() {
	log.Println("Connecting to discord")

	//var err error
	c := config.Get()
	dg, err := discordgo.New(c.Email, c.Password, c.Token)

	if err != nil {
		log.Println(err.Error())
		return
	}

	// Register messageCreate as a callback for the OnMessageCreate event.
	dg.AddHandler(messageCreate)

	// Retry after broken websocket
	dg.ShouldReconnectOnError = true

	// Open websocket connection
	err = dg.Open()
	if err != nil {
		log.Println(err)
		return
	}

	log.Println("Connected")
}
开发者ID:Xwth,项目名称:h-bot,代码行数:27,代码来源:main.go

示例7: recv

// stream receiver
func (s *server) recv(stream TunService_StreamServer, sess_die chan struct{}) chan []byte {
	ch := make(chan []byte)
	go func() {
		defer func() {
			close(ch)
		}()

		decoder, err := rc4.NewCipher([]byte(_key_recv))
		if err != nil {
			log.Println(err)
			return
		}

		for {
			in, err := stream.Recv()
			if err == io.EOF { // client closed
				log.Println(err)
				return
			}

			if err != nil {
				log.Println(err)
				return
			}

			decoder.XORKeyStream(in.Message, in.Message)
			select {
			case ch <- in.Message:
			case <-sess_die:
			}
		}
	}()
	return ch
}
开发者ID:wandison,项目名称:http2tun,代码行数:35,代码来源:service.go

示例8: buildExternal

// buildExternal downloads and builds external packages, and
// reports their build status to the dashboard.
// It will re-build all packages after pkgBuildInterval nanoseconds or
// a new release tag is found.
func (b *Builder) buildExternal() {
	var prevTag string
	var nextBuild int64
	for {
		time.Sleep(waitInterval)
		err := run(nil, goroot, "hg", "pull", "-u")
		if err != nil {
			log.Println("hg pull failed:", err)
			continue
		}
		hash, tag, err := firstTag(releaseRe)
		if err != nil {
			log.Println(err)
			continue
		}
		if *verbose {
			log.Println("latest release:", tag)
		}
		// don't rebuild if there's no new release
		// and it's been less than pkgBuildInterval
		// nanoseconds since the last build.
		if tag == prevTag && time.Nanoseconds() < nextBuild {
			continue
		}
		// build will also build the packages
		if err := b.buildHash(hash); err != nil {
			log.Println(err)
			continue
		}
		prevTag = tag
		nextBuild = time.Nanoseconds() + pkgBuildInterval
	}
}
开发者ID:vablaya,项目名称:gopp-cs345,代码行数:37,代码来源:main.go

示例9: Run

func (s *websocketService) Run() {
	defer s.conn.Close()
	defer s.Quit()
	log.Println("Upgrading connection to websocket")

	websocketErrors := make(chan error)
	go func(conn *websocket.Conn, errChan chan error) {
		for {
			var message interface{}
			err := conn.ReadJSON(&message)
			if err != nil {
				errChan <- err
				conn.Close()
				return
			}
		}
	}(s.conn, websocketErrors)

	for {
		select {
		case d := <-s.messages:
			log.Printf("Received a message: %s", d)
			s.conn.WriteJSON(d)
		case err := <-websocketErrors:
			if err != nil {
				log.Println("Closing websocket connection")
				return
			}
		}
	}
}
开发者ID:emembrives,项目名称:remote,代码行数:31,代码来源:presentation.go

示例10: Save

// Save saves all lines to the text file, excep when:
// + it starts with some space
// + it is an empty line
func (h *history) Save() (err error) {
	if _, err = h.file.Seek(0, 0); err != nil {
		return
	}

	out := bufio.NewWriter(h.file)
	element := h.li.Front() // Get the first element.

	for i := 0; i < h.li.Len(); i++ {
		line := element.Value.(string)

		if strings.HasPrefix(line, " ") {
			goto _next
		}
		if line = strings.TrimSpace(line); line == "" {
			goto _next
		}
		if _, err = out.WriteString(line + "\n"); err != nil {
			log.Println("history.Save:", err)
			break
		}

	_next:
		if element = element.Next(); element == nil {
			continue
		}
	}

	if err = out.Flush(); err != nil {
		log.Println("history.Save:", err)
	}

	h.close()
	return
}
开发者ID:rliebling,项目名称:terminal,代码行数:38,代码来源:history.go

示例11: HandleIssues

func HandleIssues(b []byte) {
	defer PanicHandler(true)
	payload, err := UnmarshalIssues(b)
	if err != nil {
		log.Println("Error decoding Commit Comment payload:", err)
		return
	}

	gu := payload.Sender
	gr := payload.Repo
	o := payload.Organization

	p, ta, err := FindIssuesPointsAndTrophyAction(payload)
	if err != nil {
		log.Println("Issues payload error:", err)
		return
	}

	user, _ := entities.NewUserWithGithubData(gu)
	repo, _ := entities.NewRepoWithGithubData(gr)
	org, _ := entities.NewOrganizationWithGithubData(o)

	err = DistributeScores(p, user, repo, org)
	if err != nil {
		log.Println("Error distributing scores:", err)
	}
	err = RegisterAction(ta, user)
	if err != nil {
		log.Println("Error registrating action:", err)
	}
}
开发者ID:tokams,项目名称:autograder,代码行数:31,代码来源:issues.go

示例12: ListenAndServe

func (s *Server) ListenAndServe() error {
	uaddr, err := net.ResolveUDPAddr("udp", s.Addr)
	if err != nil {
		return err
	}
	conn, err := net.ListenUDP("udp", uaddr)
	if err != nil {
		return err
	}
	defer conn.Close()
	log.Println("listening on", uaddr)
	newmsg := make(chan Message)
	go messageReceiver(s, newmsg)
	for {
		b := make([]byte, 1024)
		n, addr, err := conn.ReadFrom(b)
		if err != nil {
			log.Println("error %v", err)
			continue
		}
		heartbeat := Message{From: addr.String()}
		b = bytes.TrimLeft(b[:n], "\n")
		heartbeat.extract(b) // remove newline
		newmsg <- heartbeat
	}

}
开发者ID:hagna,项目名称:watchdog,代码行数:27,代码来源:watchdog.go

示例13: watchdog

func (t *timer) watchdog(remove chan Message) {
	alertcount := 0
loop:
	for {
		select {
		case ctrl := <-t.ctrl:
			switch ctrl {
			case RESET:
				t.Handler.Feed(t.Message)
				t.relight()
				alertcount = 0
			case STOP:
				break loop
			}
		case b := <-t.cupdate:
			log.Println("got update Message")
			t.Message.change(b)
		case <-t.Fuse:
			log.Println("Timeout reached", t.Message)
			t.Handler.Starve(t.Message)
			t.relight()
			alertcount++
			if alertcount > t.Alertlimit || t.Alertonce {
				log.Printf("Alert limit %d reached", t.Alertlimit)
				break loop
			}
		}
	}
	remove <- t.Message
}
开发者ID:hagna,项目名称:watchdog,代码行数:30,代码来源:watchdog.go

示例14: getFile

func getFile(filename string, cp chan *cachePutRequest, cacheCheck chan *cacheCheckRequest, fileSent chan bool) (io.Reader, error) {
	cacheReq := new(cacheCheckRequest)
	cacheReq.name = filename
	cacheReq.isNotCached = make(chan bool)
	cacheReq.isCached = make(chan *cachePutRequest)

	//send cache check request
	cacheCheck <- cacheReq
	//handle cache request
	select {
	case c := <-cacheReq.isCached:
		log.Println("Cache hit sending", c.name, "to the client")
		return c.file, nil
	case <-cacheReq.isNotCached:
		log.Println("Cache miss sending", filename, "to the client")

		fd, err := os.Open(filename)
		if err != nil {
			return fd, err
		}

		//when cacheFileReader.Read is called, responseFileReader will be written to
		responseFileReader := new(bytes.Buffer)
		cacheFileReader := io.TeeReader(fd, responseFileReader)

		cachePut := new(cachePutRequest)
		cachePut.name = filename
		cachePut.file = responseFileReader
		cachePut.fileIsSent = fileSent
		//the cache needs to know when the file has been read so it can write it to the

		cp <- cachePut
		return cacheFileReader, nil
	}
}
开发者ID:ebuckley,项目名称:slurp_server,代码行数:35,代码来源:main.go

示例15: buildOrBench

// buildOrBench checks for a new commit for this builder
// and builds or benchmarks it if one is found.
// It returns true if a build/benchmark was attempted.
func (b *Builder) buildOrBench() bool {
	var kinds []string
	if *doBuild {
		kinds = append(kinds, "build-go-commit")
	}
	if *doBench {
		kinds = append(kinds, "benchmark-go-commit")
	}
	kind, hash, benchs, err := b.todo(kinds, "", "")
	if err != nil {
		log.Println(err)
		return false
	}
	if hash == "" {
		return false
	}
	switch kind {
	case "build-go-commit":
		if err := b.buildHash(hash); err != nil {
			log.Println(err)
		}
		return true
	case "benchmark-go-commit":
		if err := b.benchHash(hash, benchs); err != nil {
			log.Println(err)
		}
		return true
	default:
		log.Println("Unknown todo kind %v", kind)
		return false
	}
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:35,代码来源:main.go


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