本文整理汇总了Golang中github.com/Kissaki/log4go.Info函数的典型用法代码示例。如果您正苦于以下问题:Golang Info函数的具体用法?Golang Info怎么用?Golang Info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Info函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RegisterTemp
// RegisterTmp create a ephemeral node, and watch it, if node droped then send a SIGQUIT to self.
func RegisterTemp(conn *zk.Conn, fpath string, data []byte) error {
tpath, err := conn.Create(path.Join(fpath)+"/", data, zk.FlagEphemeral|zk.FlagSequence, zk.WorldACL(zk.PermAll))
if err != nil {
log.Error("conn.Create(\"%s\", \"%s\", zk.FlagEphemeral|zk.FlagSequence) error(%v)", fpath, string(data), err)
return err
}
log.Debug("create a zookeeper node:%s", tpath)
// watch self
go func() {
for {
log.Info("zk path: \"%s\" set a watch", tpath)
exist, _, watch, err := conn.ExistsW(tpath)
if err != nil {
log.Error("zk.ExistsW(\"%s\") error(%v)", tpath, err)
log.Warn("zk path: \"%s\" set watch failed, kill itself", tpath)
killSelf()
return
}
if !exist {
log.Warn("zk path: \"%s\" not exist, kill itself", tpath)
killSelf()
return
}
event := <-watch
log.Info("zk path: \"%s\" receive a event %v", tpath, event)
}
}()
return nil
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:30,代码来源:zk.go
示例2: main
func main() {
var err error
// Parse cmd-line arguments
flag.Parse()
log.Info("web ver: \"%s\" start", ver.Version)
if err = InitConfig(); err != nil {
panic(err)
}
// Set max routine
runtime.GOMAXPROCS(Conf.MaxProc)
// init log
log.LoadConfiguration(Conf.Log)
defer log.Close()
// init zookeeper
zkConn, err := InitZK()
if err != nil {
if zkConn != nil {
zkConn.Close()
}
panic(err)
}
// start pprof http
perf.Init(Conf.PprofBind)
// start http listen.
StartHTTP()
// process init
if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil {
panic(err)
}
// init signals, block wait signals
signalCH := InitSignal()
HandleSignal(signalCH)
log.Info("web stop")
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:34,代码来源:main.go
示例3: Get
// Get a user channel from ChannleList.
func (l *ChannelList) Get(key string, newOne bool) (Channel, error) {
// validate
if err := l.validate(key); err != nil {
return nil, err
}
// get a channel bucket
b := l.Bucket(key)
b.Lock()
if c, ok := b.Data[key]; !ok {
if !Conf.Auth && newOne {
c = NewSeqChannel()
b.Data[key] = c
b.Unlock()
ChStat.IncrCreate()
log.Info("user_key:\"%s\" create a new channel", key)
return c, nil
} else {
b.Unlock()
log.Warn("user_key:\"%s\" channle not exists", key)
return nil, ErrChannelNotExist
}
} else {
b.Unlock()
ChStat.IncrAccess()
log.Info("user_key:\"%s\" refresh channel bucket expire time", key)
return c, nil
}
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:29,代码来源:channel.go
示例4: StartHTTP
// StartHTTP start listen http.
func StartHTTP() {
// external
httpServeMux := http.NewServeMux()
// 2
httpServeMux.HandleFunc("/2/server/get", GetServer2)
// 1.0
httpServeMux.HandleFunc("/1/server/get", GetServer)
httpServeMux.HandleFunc("/1/msg/get", GetOfflineMsg)
httpServeMux.HandleFunc("/1/time/get", GetTime)
// old
httpServeMux.HandleFunc("/server/get", GetServer0)
httpServeMux.HandleFunc("/msg/get", GetOfflineMsg0)
httpServeMux.HandleFunc("/time/get", GetTime0)
// internal
httpAdminServeMux := http.NewServeMux()
// 1.0
httpAdminServeMux.HandleFunc("/1/admin/push/private", PushPrivate)
httpAdminServeMux.HandleFunc("/1/admin/push/mprivate", PushMultiPrivate)
httpAdminServeMux.HandleFunc("/1/admin/msg/del", DelPrivate)
// old
httpAdminServeMux.HandleFunc("/admin/push", PushPrivate)
httpAdminServeMux.HandleFunc("/admin/msg/clean", DelPrivate)
for _, bind := range Conf.HttpBind {
log.Info("start http listen addr:\"%s\"", bind)
go httpListen(httpServeMux, bind)
}
for _, bind := range Conf.AdminBind {
log.Info("start admin http listen addr:\"%s\"", bind)
go httpListen(httpAdminServeMux, bind)
}
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:32,代码来源:http.go
示例5: Migrate
// Migrate migrate portion of connections which don't belong to this comet.
func (l *ChannelList) Migrate(nw map[string]int) (err error) {
migrate := false
// check new/update node
for k, v := range nw {
weight, ok := nodeWeightMap[k]
// not found or weight change
if !ok || weight != v {
migrate = true
break
}
}
// check del node
if !migrate {
for k, _ := range nodeWeightMap {
// node deleted
if _, ok := nw[k]; !ok {
migrate = true
break
}
}
}
if !migrate {
return
}
// init ketama
ring := ketama.NewRing(ketama.Base)
for node, weight := range nw {
ring.AddNode(node, weight)
}
ring.Bake()
// atomic update
nodeWeightMap = nw
CometRing = ring
// get all the channel lock
channels := []Channel{}
for i, c := range l.Channels {
c.Lock()
for k, v := range c.Data {
hn := ring.Hash(k)
if hn != Conf.ZookeeperCometNode {
channels = append(channels, v)
delete(c.Data, k)
log.Debug("migrate delete channel key \"%s\"", k)
}
}
c.Unlock()
log.Debug("migrate channel bucket:%d finished", i)
}
// close all the migrate channels
log.Info("close all the migrate channels")
for _, channel := range channels {
if err := channel.Close(); err != nil {
log.Error("channel.Close() error(%v)", err)
continue
}
}
log.Info("close all the migrate channels finished")
return
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:60,代码来源:channel.go
示例6: watchCometNode
// watchNode watch a named node for leader selection when failover
func watchCometNode(conn *zk.Conn, node, fpath string, retry, ping time.Duration, ch chan *CometNodeEvent) {
fpath = path.Join(fpath, node)
for {
nodes, watch, err := myzk.GetNodesW(conn, fpath)
if err == myzk.ErrNodeNotExist {
log.Warn("zk don't have node \"%s\"", fpath)
break
} else if err == myzk.ErrNoChild {
log.Warn("zk don't have any children in \"%s\", retry in %d second", fpath, waitNodeDelay)
time.Sleep(waitNodeDelaySecond)
continue
} else if err != nil {
log.Error("zk path: \"%s\" getNodes error(%v), retry in %d second", fpath, err, waitNodeDelay)
time.Sleep(waitNodeDelaySecond)
continue
}
// leader selection
sort.Strings(nodes)
if info, err := registerCometNode(conn, nodes[0], fpath, retry, ping, true); err != nil {
log.Error("zk path: \"%s\" registerCometNode error(%v)", fpath, err)
time.Sleep(waitNodeDelaySecond)
continue
} else {
// update node info
ch <- &CometNodeEvent{Event: eventNodeUpdate, Key: node, Value: info}
}
// blocking receive event
event := <-watch
log.Info("zk path: \"%s\" receive a event: (%v)", fpath, event)
}
// WARN, if no persistence node and comet rpc not config
log.Warn("zk path: \"%s\" never watch again till recreate", fpath)
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:34,代码来源:comet.go
示例7: StartStats
// start stats, called at process start
func StartStats() {
startTime = time.Now().UnixNano()
for _, bind := range Conf.StatBind {
log.Info("start stat listen addr:\"%s\"", bind)
go statListen(bind)
}
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:8,代码来源:stat.go
示例8: StartWebsocket
// StartHttp start http listen.
func StartWebsocket() error {
for _, bind := range Conf.WebsocketBind {
log.Info("start websocket listen addr:\"%s\"", bind)
go websocketListen(bind)
}
return nil
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:9,代码来源:pubsub_websocket.go
示例9: StartTCP
// StartTCP Start tcp listen.
func StartTCP() error {
for _, bind := range Conf.TCPBind {
log.Info("start tcp listen addr:\"%s\"", bind)
go tcpListen(bind)
}
return nil
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:9,代码来源:pubsub_tcp.go
示例10: StartRPC
// StartRPC start rpc listen.
func StartRPC() error {
c := &CometRPC{}
rpc.Register(c)
for _, bind := range Conf.RPCBind {
log.Info("start listen rpc addr: \"%s\"", bind)
go rpcListen(bind)
}
return nil
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:11,代码来源:rpc.go
示例11: InitRPC
// InitRPC start accept rpc call.
func InitRPC() error {
msg := &MessageRPC{}
rpc.Register(msg)
for _, bind := range Conf.RPCBind {
log.Info("start rpc listen addr: \"%s\"", bind)
go rpcListen(bind)
}
return nil
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:11,代码来源:rpc.go
示例12: tcpListen
func tcpListen(bind string) {
addr, err := net.ResolveTCPAddr("tcp", bind)
if err != nil {
log.Error("net.ResolveTCPAddr(\"tcp\"), %s) error(%v)", bind, err)
panic(err)
}
l, err := net.ListenTCP("tcp", addr)
if err != nil {
log.Error("net.ListenTCP(\"tcp4\", \"%s\") error(%v)", bind, err)
panic(err)
}
// free the listener resource
defer func() {
log.Info("tcp addr: \"%s\" close", bind)
if err := l.Close(); err != nil {
log.Error("listener.Close() error(%v)", err)
}
}()
// init reader buffer instance
rb := newtcpBufCache()
for {
log.Debug("start accept")
conn, err := l.AcceptTCP()
if err != nil {
log.Error("listener.AcceptTCP() error(%v)", err)
continue
}
if err = conn.SetKeepAlive(Conf.TCPKeepalive); err != nil {
log.Error("conn.SetKeepAlive() error(%v)", err)
conn.Close()
continue
}
if err = conn.SetReadBuffer(Conf.RcvbufSize); err != nil {
log.Error("conn.SetReadBuffer(%d) error(%v)", Conf.RcvbufSize, err)
conn.Close()
continue
}
if err = conn.SetWriteBuffer(Conf.SndbufSize); err != nil {
log.Error("conn.SetWriteBuffer(%d) error(%v)", Conf.SndbufSize, err)
conn.Close()
continue
}
// first packet must sent by client in specified seconds
if err = conn.SetReadDeadline(time.Now().Add(fitstPacketTimedoutSec)); err != nil {
log.Error("conn.SetReadDeadLine() error(%v)", err)
conn.Close()
continue
}
rc := rb.Get()
// one connection one routine
go handleTCPConn(conn, rc)
log.Debug("accept finished")
}
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:54,代码来源:pubsub_tcp.go
示例13: watchMessageRoot
// watchMessageRoot watch the message root path.
func watchMessageRoot(conn *zk.Conn, fpath string, ch chan *MessageNodeEvent) error {
for {
nodes, watch, err := myzk.GetNodesW(conn, fpath)
if err == myzk.ErrNodeNotExist {
log.Warn("zk don't have node \"%s\", retry in %d second", fpath, waitNodeDelay)
time.Sleep(waitNodeDelaySecond)
continue
} else if err == myzk.ErrNoChild {
log.Warn("zk don't have any children in \"%s\", retry in %d second", fpath, waitNodeDelay)
// all child died, kick all the nodes
for _, client := range MessageRPC.Clients {
log.Debug("node: \"%s\" send del node event", client.Addr)
ch <- &MessageNodeEvent{Event: eventNodeDel, Key: &WeightRpc{Addr: client.Addr, Weight: client.Weight}}
}
time.Sleep(waitNodeDelaySecond)
continue
} else if err != nil {
log.Error("getNodes error(%v), retry in %d second", err, waitNodeDelay)
time.Sleep(waitNodeDelaySecond)
continue
}
nodesMap := map[string]bool{}
// handle new add nodes
for _, node := range nodes {
data, _, err := conn.Get(path.Join(fpath, node))
if err != nil {
log.Error("zk.Get(\"%s\") error(%v)", path.Join(fpath, node), err)
continue
}
// parse message node info
nodeInfo := &MessageNodeInfo{}
if err := json.Unmarshal(data, nodeInfo); err != nil {
log.Error("json.Unmarshal(\"%s\", nodeInfo) error(%v)", string(data), err)
continue
}
for _, addr := range nodeInfo.Rpc {
// if not exists in old map then trigger a add event
if _, ok := MessageRPC.Clients[addr]; !ok {
ch <- &MessageNodeEvent{Event: eventNodeAdd, Key: &WeightRpc{Addr: addr, Weight: nodeInfo.Weight}}
}
nodesMap[addr] = true
}
}
// handle delete nodes
for _, client := range MessageRPC.Clients {
if _, ok := nodesMap[client.Addr]; !ok {
ch <- &MessageNodeEvent{Event: eventNodeDel, Key: client}
}
}
// blocking wait node changed
event := <-watch
log.Info("zk path: \"%s\" receive a event %v", fpath, event)
}
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:55,代码来源:message.go
示例14: handleMessageNodeEvent
// handleNodeEvent add and remove MessageRPC.Clients, copy the src map to a new map then replace the variable.
func handleMessageNodeEvent(conn *zk.Conn, retry, ping time.Duration, ch chan *MessageNodeEvent) {
for {
ev := <-ch
// copy map from src
tmpMessageRPCMap := make(map[string]*WeightRpc, len(MessageRPC.Clients))
for k, v := range MessageRPC.Clients {
tmpMessageRPCMap[k] = &WeightRpc{Client: v.Client, Addr: v.Addr, Weight: v.Weight}
// reuse rpc connection
v.Client = nil
}
// handle event
if ev.Event == eventNodeAdd {
log.Info("add message rpc node: \"%s\"", ev.Key.Addr)
rpcTmp, err := rpc.Dial("tcp", ev.Key.Addr)
if err != nil {
log.Error("rpc.Dial(\"tcp\", \"%s\") error(%v)", ev.Key, err)
log.Warn("discard message rpc node: \"%s\", connect failed", ev.Key)
continue
}
ev.Key.Client = rpcTmp
tmpMessageRPCMap[ev.Key.Addr] = ev.Key
} else if ev.Event == eventNodeDel {
log.Info("del message rpc node: \"%s\"", ev.Key.Addr)
delete(tmpMessageRPCMap, ev.Key.Addr)
} else {
log.Error("unknown node event: %d", ev.Event)
panic("unknown node event")
}
tmpMessageRPC, err := NewRandLB(tmpMessageRPCMap, MessageService, retry, ping, true)
if err != nil {
log.Error("NewRandLR() error(%v)", err)
panic(err)
}
oldMessageRPC := MessageRPC
// atomic update
MessageRPC = tmpMessageRPC
// release resource
oldMessageRPC.Destroy()
log.Debug("MessageRPC.Client length: %d", len(MessageRPC.Clients))
}
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:42,代码来源:message.go
示例15: registerCometNode
// registerCometNode get infomation of comet node
func registerCometNode(conn *zk.Conn, node, fpath string, retry, ping time.Duration, startPing bool) (info *CometNodeInfo, err error) {
// get current node info from zookeeper
fpath = path.Join(fpath, node)
data, _, err := conn.Get(fpath)
if err != nil {
log.Error("zk.Get(\"%s\") error(%v)", fpath, err)
return
}
info = &CometNodeInfo{}
if err = json.Unmarshal(data, info); err != nil {
log.Error("json.Unmarshal(\"%s\", nodeData) error(%v)", string(data), err)
return
}
if len(info.RpcAddr) == 0 {
log.Error("zk nodes: \"%s\" don't have rpc addr", fpath)
err = ErrCometRPC
return
}
// get old node info for finding the old rpc connection
oldInfo := cometNodeInfoMap[node]
// init comet rpc
clients := make(map[string]*WeightRpc, len(info.RpcAddr))
for _, addr := range info.RpcAddr {
var (
r *rpc.Client
)
if oldInfo != nil && oldInfo.Rpc != nil {
if wr, ok := oldInfo.Rpc.Clients[addr]; ok && wr.Client != nil {
// reuse the rpc connection must let old client = nil, avoid reclose rpc.
oldInfo.Rpc.Clients[addr].Client = nil
r = wr.Client
}
}
if r == nil {
if r, err = rpc.Dial("tcp", addr); err != nil {
log.Error("rpc.Dial(\"%s\") error(%v)", addr, err)
return
}
log.Debug("node:%s addr:%s rpc reconnect", node, addr)
}
clients[addr] = &WeightRpc{Weight: 1, Addr: addr, Client: r}
}
// comet rpc use rand load balance
lb, err := NewRandLB(clients, cometService, retry, ping, startPing)
if err != nil {
log.Error("NewRandLR() error(%v)", err)
return
}
info.Rpc = lb
log.Info("zk path: \"%s\" register nodes: \"%s\"", fpath, node)
return
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:53,代码来源:comet.go
示例16: New
// New create a user channle.
func (l *ChannelList) New(key string) (Channel, *ChannelBucket, error) {
// validate
if err := l.validate(key); err != nil {
return nil, nil, err
}
// get a channel bucket
b := l.Bucket(key)
b.Lock()
if c, ok := b.Data[key]; ok {
b.Unlock()
ChStat.IncrAccess()
log.Info("user_key:\"%s\" refresh channel bucket expire time", key)
return c, b, nil
} else {
c = NewSeqChannel()
b.Data[key] = c
b.Unlock()
ChStat.IncrCreate()
log.Info("user_key:\"%s\" create a new channel", key)
return c, b, nil
}
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:23,代码来源:channel.go
示例17: RemoveConn
// RemoveConn implements the Channel RemoveConn method.
func (c *SeqChannel) RemoveConn(key string, e *hlist.Element) error {
c.mutex.Lock()
tmp := c.conn.Remove(e)
c.mutex.Unlock()
conn, ok := tmp.(*Connection)
if !ok {
return ErrAssectionConn
}
close(conn.Buf)
ConnStat.IncrRemove()
log.Info("user_key:\"%s\" remove conn = %d", key, c.conn.Len())
return nil
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:14,代码来源:seq_channel.go
示例18: getConn
// getConn get the connection of matching with key using ketama hash
func (s *MySQLStorage) getConn(key string) *sql.DB {
if len(s.pool) == 0 {
return nil
}
node := s.ring.Hash(key)
p, ok := s.pool[node]
if !ok {
log.Warn("user_key: \"%s\" hit mysql node: \"%s\" not in pool", key, node)
return nil
}
log.Info("user_key: \"%s\" hit mysql node: \"%s\"", key, node)
return p
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:14,代码来源:mysql.go
示例19: clean
// clean delete expired messages peroridly.
func (s *MySQLStorage) clean() {
for {
log.Info("clean mysql expired message start")
now := time.Now().Unix()
affect := int64(0)
for _, db := range s.pool {
res, err := db.Exec(delExpiredPrivateMsgSQL, now)
if err != nil {
log.Error("db.Exec(\"%s\", %d) failed (%v)", delExpiredPrivateMsgSQL, now, err)
continue
}
aff, err := res.RowsAffected()
if err != nil {
log.Error("res.RowsAffected() error(%v)", err)
continue
}
affect += aff
}
log.Info("clean mysql expired message finish, num: %d", affect)
time.Sleep(Conf.MySQLClean)
}
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:23,代码来源:mysql.go
示例20: retPWrite
// retPWrite marshal the result and write to client(post).
func retPWrite(w http.ResponseWriter, r *http.Request, res map[string]interface{}, body *string, start time.Time) {
data, err := json.Marshal(res)
if err != nil {
log.Error("json.Marshal(\"%v\") error(%v)", res, err)
return
}
dataStr := string(data)
if n, err := w.Write([]byte(dataStr)); err != nil {
log.Error("w.Write(\"%s\") error(%v)", dataStr, err)
} else {
log.Debug("w.Write(\"%s\") write %d bytes", dataStr, n)
}
log.Info("req: \"%s\", post: \"%s\", res:\"%s\", ip:\"%s\", time:\"%fs\"", r.URL.String(), *body, dataStr, r.RemoteAddr, time.Now().Sub(start).Seconds())
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:15,代码来源:http.go
注:本文中的github.com/Kissaki/log4go.Info函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论