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


Golang log.Infof函數代碼示例

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


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

示例1: daemonSyncMaster

func (h *Handler) daemonSyncMaster() {
	var last *conn
	wait := make(chan int, 0)
	for exit := false; !exit; {
		var c *conn
		select {
		case <-wait:
			last = nil
		case <-h.signal:
			exit = true
		case c = <-h.master:
		}
		if last != nil {
			last.Close()
			<-wait
		}
		last = c
		if c != nil {
			go func() {
				defer func() {
					wait <- 0
				}()
				defer c.Close()
				err := h.doSyncTo(c)
				log.InfoErrorf(err, "stop sync: %s", c.summ)
			}()
			h.syncto = c.nc.RemoteAddr().String()
			log.Infof("sync to %s", h.syncto)
		} else {
			h.syncto = ""
			log.Infof("sync to no one")
		}
	}
}
開發者ID:fengshao0907,項目名稱:rpdb,代碼行數:34,代碼來源:sync.go

示例2: Reset

func (b *Rpdb) Reset() error {
	if err := b.acquire(); err != nil {
		return err
	}
	defer b.release()
	log.Infof("rpdb is reseting...")
	for i := b.splist.Len(); i != 0; i-- {
		v := b.splist.Remove(b.splist.Front()).(*RpdbSnapshot)
		v.Close()
	}
	for i := b.itlist.Len(); i != 0; i-- {
		v := b.itlist.Remove(b.itlist.Front()).(*rpdbIterator)
		v.Close()
	}
	if err := b.db.Clear(); err != nil {
		b.db.Close()
		b.db = nil
		log.ErrorErrorf(err, "rpdb reset failed")
		return err
	} else {
		b.serial++
		log.Infof("rpdb is reset")
		return nil
	}
}
開發者ID:fengshao0907,項目名稱:rpdb,代碼行數:25,代碼來源:rpdb.go

示例3: Main

func (cmd *cmdDump) Main() {
	from, output := args.from, args.output
	if len(from) == 0 {
		log.Panic("invalid argument: from")
	}
	if len(output) == 0 {
		output = "/dev/stdout"
	}

	log.Infof("dump from '%s' to '%s'\n", from, output)

	var dumpto io.WriteCloser
	if output != "/dev/stdout" {
		dumpto = openWriteFile(output)
		defer dumpto.Close()
	} else {
		dumpto = os.Stdout
	}

	master, nsize := cmd.SendCmd(from, args.passwd)
	defer master.Close()

	log.Infof("rdb file = %d\n", nsize)

	reader := bufio.NewReaderSize(master, ReaderBufferSize)
	writer := bufio.NewWriterSize(dumpto, WriterBufferSize)

	cmd.DumpRDBFile(reader, writer, nsize)

	if !args.extra {
		return
	}

	cmd.DumpCommand(reader, writer, nsize)
}
開發者ID:TigerZhang,項目名稱:redis-port,代碼行數:35,代碼來源:dump.go

示例4: SendPSyncCmd

func (cmd *cmdSync) SendPSyncCmd(master, passwd string) (pipe.Reader, int64) {
	c := openNetConn(master, passwd)
	br := bufio.NewReaderSize(c, ReaderBufferSize)
	bw := bufio.NewWriterSize(c, WriterBufferSize)

	runid, offset, wait := sendPSyncFullsync(br, bw)
	log.Infof("psync runid = %s offset = %d, fullsync", runid, offset)

	var nsize int64
	for nsize == 0 {
		select {
		case nsize = <-wait:
			if nsize == 0 {
				log.Info("+")
			}
		case <-time.After(time.Second):
			log.Info("-")
		}
	}

	piper, pipew := pipe.NewSize(ReaderBufferSize)

	go func() {
		defer pipew.Close()
		p := make([]byte, 8192)
		for rdbsize := int(nsize); rdbsize != 0; {
			rdbsize -= iocopy(br, pipew, p, rdbsize)
		}
		for {
			n, err := cmd.PSyncPipeCopy(c, br, bw, offset, pipew)
			if err != nil {
				log.PanicErrorf(err, "psync runid = %s, offset = %d, pipe is broken", runid, offset)
			}
			offset += n
			for {
				time.Sleep(time.Second)
				c = openNetConnSoft(master, passwd)
				if c != nil {
					log.Infof("psync reopen connection, offset = %d", offset)
					break
				} else {
					log.Infof("psync reopen connection, failed")
				}
			}
			authPassword(c, passwd)
			br = bufio.NewReaderSize(c, ReaderBufferSize)
			bw = bufio.NewWriterSize(c, WriterBufferSize)
			sendPSyncContinue(br, bw, runid, offset)
		}
	}()
	return piper, nsize
}
開發者ID:morya,項目名稱:redis-port,代碼行數:52,代碼來源:sync.go

示例5: CompactAll

func (b *Rpdb) CompactAll() error {
	if err := b.acquire(); err != nil {
		return err
	}
	defer b.release()
	log.Infof("rpdb is compacting all...")
	if err := b.compact([]byte{MetaCode}, []byte{MetaCode + 1}); err != nil {
		return err
	}
	if err := b.compact([]byte{DataCode}, []byte{DataCode + 1}); err != nil {
		return err
	}
	log.Infof("rpdb is compacted")
	return nil
}
開發者ID:fengshao0907,項目名稱:rpdb,代碼行數:15,代碼來源:keys.go

示例6: Serve

func Serve(config *Config, bl *rpdb.Rpdb) error {
	h := &Handler{
		config: config,
		master: make(chan *conn, 0),
		signal: make(chan int, 0),
	}
	defer func() {
		close(h.signal)
	}()

	l, err := net.Listen("tcp", config.Listen)
	if err != nil {
		return errors.Trace(err)
	}
	defer l.Close()

	if h.htable, err = redis.NewHandlerTable(h); err != nil {
		return err
	} else {
		go h.daemonSyncMaster()
	}

	log.Infof("open listen address '%s' and start service", l.Addr())

	for {
		if nc, err := l.Accept(); err != nil {
			return errors.Trace(err)
		} else {
			h.counters.clientsAccepted.Add(1)
			go func() {
				h.counters.clients.Add(1)
				defer h.counters.clients.Sub(1)
				c := newConn(nc, bl, h.config.ConnTimeout)
				defer c.Close()
				log.Infof("new connection: %s", c.summ)
				if err := c.serve(h); err != nil {
					if errors.Equal(err, io.EOF) {
						log.Infof("connection lost: %s [io.EOF]", c.summ)
					} else {
						log.InfoErrorf(err, "connection lost: %s", c.summ)
					}
				} else {
					log.Infof("connection exit: %s", c.summ)
				}
			}()
		}
	}
}
開發者ID:fengshao0907,項目名稱:rpdb,代碼行數:48,代碼來源:main.go

示例7: SlaveOf

// SLAVEOF host port
func (h *Handler) SlaveOf(arg0 interface{}, args [][]byte) (redis.Resp, error) {
	if len(args) != 2 {
		return toRespErrorf("len(args) = %d, expect = 2", len(args))
	}

	s, err := session(arg0, args)
	if err != nil {
		return toRespError(err)
	}

	addr := fmt.Sprintf("%s:%s", string(args[0]), string(args[1]))
	log.Infof("set slave of %s", addr)

	var c *conn
	if strings.ToLower(addr) != "no:one" {
		if nc, err := net.DialTimeout("tcp", addr, time.Second); err != nil {
			return toRespError(errors.Trace(err))
		} else {
			c = newConn(nc, s.Rpdb(), 0)
			if err := c.ping(); err != nil {
				c.Close()
				return toRespError(err)
			}
		}
	}
	select {
	case <-h.signal:
		if c != nil {
			c.Close()
		}
		return toRespErrorf("sync master has been closed")
	case h.master <- c:
		return redis.NewString("OK"), nil
	}
}
開發者ID:fengshao0907,項目名稱:rpdb,代碼行數:36,代碼來源:sync.go

示例8: init

func init() {
	poolmap.m = make(map[string]*list.List)
	go func() {
		for {
			time.Sleep(time.Second)
			poolmap.Lock()
			for addr, pool := range poolmap.m {
				for i := pool.Len(); i != 0; i-- {
					c := pool.Remove(pool.Front()).(*conn)
					if time.Now().Before(c.last.Add(time.Second * 5)) {
						pool.PushBack(c)
					} else {
						c.sock.Close()
						log.Infof("close connection %s : %s", addr, c.summ)
					}
				}
				if pool.Len() != 0 {
					continue
				}
				delete(poolmap.m, addr)
			}
			poolmap.Unlock()
		}
	}()
}
開發者ID:fengshao0907,項目名稱:rpdb,代碼行數:25,代碼來源:migrate.go

示例9: Main

func (cmd *cmdRestore) Main() {
	input, target := args.input, args.target
	if len(target) == 0 {
		log.Panic("invalid argument: target")
	}
	if len(input) == 0 {
		input = "/dev/stdin"
	}

	log.Infof("restore from '%s' to '%s'\n", input, target)

	var readin io.ReadCloser
	var nsize int64
	if input != "/dev/stdin" {
		readin, nsize = openReadFile(input)
		defer readin.Close()
	} else {
		readin, nsize = os.Stdin, 0
	}

	reader := bufio.NewReaderSize(readin, ReaderBufferSize)

	cmd.RestoreRDBFile(reader, target, args.auth, nsize)

	if !args.extra {
		return
	}

	if nsize != 0 && nsize == cmd.rbytes.Get() {
		return
	}

	cmd.RestoreCommand(reader, target, args.auth)
}
開發者ID:morya,項目名稱:redis-port,代碼行數:34,代碼來源:restore.go

示例10: DumpRDBFile

func (cmd *cmdDump) DumpRDBFile(reader *bufio.Reader, writer *bufio.Writer, nsize int64) {
	var nread atomic2.Int64
	wait := make(chan struct{})
	go func() {
		defer close(wait)
		p := make([]byte, WriterBufferSize)
		for nsize != nread.Get() {
			nstep := int(nsize - nread.Get())
			ncopy := int64(iocopy(reader, writer, p, nstep))
			nread.Add(ncopy)
			flushWriter(writer)
		}
	}()

	for done := false; !done; {
		select {
		case <-wait:
			done = true
		case <-time.After(time.Second):
		}
		n := nread.Get()
		p := 100 * n / nsize
		log.Infof("total = %d - %12d [%3d%%]\n", nsize, n, p)
	}
	log.Info("dump: rdb done")
}
開發者ID:TigerZhang,項目名稱:redis-port,代碼行數:26,代碼來源:dump.go

示例11: Main

func (cmd *cmdSync) Main() {
	from, target := args.from, args.target
	if len(from) == 0 {
		log.Panic("invalid argument: from")
	}
	if len(target) == 0 {
		log.Panic("invalid argument: target")
	}

	log.Infof("sync from '%s' to '%s'\n", from, target)

	var sockfile *os.File
	if len(args.sockfile) != 0 {
		sockfile = openReadWriteFile(args.sockfile)
		defer sockfile.Close()
	}

	var input io.ReadCloser
	var nsize int64
	if args.psync {
		input, nsize = cmd.SendPSyncCmd(from, args.passwd)
	} else {
		input, nsize = cmd.SendSyncCmd(from, args.passwd)
	}
	defer input.Close()

	log.Infof("rdb file = %d\n", nsize)

	if sockfile != nil {
		r, w := pipe.NewFilePipe(int(args.filesize), sockfile)
		defer r.Close()
		go func(r io.Reader) {
			defer w.Close()
			p := make([]byte, ReaderBufferSize)
			for {
				iocopy(r, w, p, len(p))
			}
		}(input)
		input = r
	}

	reader := bufio.NewReaderSize(input, ReaderBufferSize)

	cmd.SyncRDBFile(reader, target, args.auth, nsize)
	cmd.SyncCommand(reader, target, args.auth)
}
開發者ID:morya,項目名稱:redis-port,代碼行數:46,代碼來源:sync.go

示例12: Close

func (s *RpdbSnapshot) Close() {
	if err := s.acquire(); err != nil {
		return
	}
	defer s.release()
	log.Infof("snapshot is closing ...")
	if s.cursor.it != nil {
		s.cursor.it.Close()
		s.cursor.it = nil
	}
	for i := s.readers.Len(); i != 0; i-- {
		r := s.readers.Remove(s.readers.Front()).(*snapshotReader)
		r.cleanup()
	}
	s.sp.Close()
	s.sp = nil
	log.Infof("snapshot is closed")
}
開發者ID:fengshao0907,項目名稱:rpdb,代碼行數:18,代碼來源:snapshot.go

示例13: NewSnapshot

func (b *Rpdb) NewSnapshot() (*RpdbSnapshot, error) {
	if err := b.acquire(); err != nil {
		return nil, err
	}
	defer b.release()
	sp := &RpdbSnapshot{sp: b.db.NewSnapshot()}
	b.splist.PushBack(sp)
	log.Infof("rpdb create new snapshot, address = %p", sp)
	return sp, nil
}
開發者ID:fengshao0907,項目名稱:rpdb,代碼行數:10,代碼來源:rpdb.go

示例14: Close

func (b *Rpdb) Close() {
	if err := b.acquire(); err != nil {
		return
	}
	defer b.release()
	log.Infof("rpdb is closing ...")
	for i := b.splist.Len(); i != 0; i-- {
		v := b.splist.Remove(b.splist.Front()).(*RpdbSnapshot)
		v.Close()
	}
	for i := b.itlist.Len(); i != 0; i-- {
		v := b.itlist.Remove(b.itlist.Front()).(*rpdbIterator)
		v.Close()
	}
	if b.db != nil {
		b.db.Close()
		b.db = nil
	}
	log.Infof("rpdb is closed")
}
開發者ID:fengshao0907,項目名稱:rpdb,代碼行數:20,代碼來源:rpdb.go

示例15: ReleaseSnapshot

func (b *Rpdb) ReleaseSnapshot(sp *RpdbSnapshot) {
	if err := b.acquire(); err != nil {
		return
	}
	defer b.release()
	log.Infof("rpdb release snapshot, address = %p", sp)
	for i := b.splist.Len(); i != 0; i-- {
		v := b.splist.Remove(b.splist.Front()).(*RpdbSnapshot)
		if v != sp {
			b.splist.PushBack(v)
		}
	}
	sp.Close()
}
開發者ID:fengshao0907,項目名稱:rpdb,代碼行數:14,代碼來源:rpdb.go


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