Commit b796edc5 authored by AlexStocks's avatar AlexStocks

change error format

parent f36fc366
......@@ -132,7 +132,7 @@ func (c *client) dialTCP() Session {
return newTCPSession(conn, c.endPointType)
}
log.Info("net.DialTimeout(addr:%s, timeout:%v) = error{%v}", c.addr, err)
log.Info("net.DialTimeout(addr:%s, timeout:%v) = error{%s}", c.addr, err)
time.Sleep(connInterval)
}
}
......@@ -159,7 +159,7 @@ func (c *client) dialUDP() Session {
return newUDPSession(conn, c.endPointType)
}
log.Info("net.DialTimeout(addr:%s, timeout:%v) = error{%v}", c.addr, err)
log.Info("net.DialTimeout(addr:%s, timeout:%v) = error{%s}", c.addr, err)
time.Sleep(connInterval)
}
}
......@@ -178,7 +178,7 @@ func (c *client) dialWS() Session {
return nil
}
conn, _, err = dialer.Dial(c.addr, nil)
log.Info("websocket.dialer.Dial(addr:%s) = error{%v}", c.addr, err)
log.Info("websocket.dialer.Dial(addr:%s) = error:%s", c.addr, err)
if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() {
err = errSelfConnect
}
......@@ -191,7 +191,7 @@ func (c *client) dialWS() Session {
return ss
}
log.Info("websocket.dialer.Dial(addr:%s) = error{%v}", c.addr, err)
log.Info("websocket.dialer.Dial(addr:%s) = error:%s", c.addr, err)
time.Sleep(connInterval)
}
}
......@@ -217,7 +217,7 @@ func (c *client) dialWSS() Session {
if c.cert != "" {
certPEMBlock, err := ioutil.ReadFile(c.cert)
if err != nil {
panic(fmt.Sprintf("ioutil.ReadFile(cert:%s) = error{%#v}", c.cert, err))
panic(fmt.Sprintf("ioutil.ReadFile(cert:%s) = error{%s}", c.cert, err))
}
var cert tls.Certificate
......@@ -239,7 +239,7 @@ func (c *client) dialWSS() Session {
for _, c := range config.Certificates {
roots, err = x509.ParseCertificates(c.Certificate[len(c.Certificate)-1])
if err != nil {
panic(fmt.Sprintf("error parsing server's root cert: %v\n", err))
panic(fmt.Sprintf("error parsing server's root cert: %s\n", err))
}
for _, root = range roots {
certPool.AddCert(root)
......@@ -268,7 +268,7 @@ func (c *client) dialWSS() Session {
return ss
}
log.Info("websocket.dialer.Dial(addr:%s) = error{%v}", c.addr, err)
log.Info("websocket.dialer.Dial(addr:%s) = error{%s}", c.addr, err)
time.Sleep(connInterval)
}
}
......
......@@ -246,7 +246,7 @@ func (t *gettyTCPConn) read(p []byte) (int, error) {
}
length, err = t.reader.Read(p)
log.Debug("now:%s, length:%d, err:%#v", currentTime, length, err)
log.Debug("now:%s, length:%d, err:%s", currentTime, length, err)
atomic.AddUint32(&t.readCount, uint32(length))
return length, err
}
......@@ -278,7 +278,7 @@ func (t *gettyTCPConn) Write(pkg interface{}) (int, error) {
atomic.AddUint32(&t.writeCount, (uint32)(len(p)))
length, err := t.writer.Write(p)
log.Debug("now:%s, length:%d, err:%#v", currentTime, length, err)
log.Debug("now:%s, length:%d, err:%s", currentTime, length, err)
return length, err
}
......@@ -291,7 +291,7 @@ func (t *gettyTCPConn) close(waitSec int) {
if t.conn != nil {
if writer, ok := t.writer.(*snappy.Writer); ok {
if err := writer.Close(); err != nil {
log.Error("snappy.Writer.Close() = error{%v}", err)
log.Error("snappy.Writer.Close() = error{%s}", err)
}
}
t.conn.(*net.TCPConn).SetLinger(waitSec)
......@@ -392,7 +392,7 @@ func (u *gettyUDPConn) read(p []byte) (int, *net.UDPAddr, error) {
} else {
length, addr, err = u.conn.ReadFromUDP(p)
}
log.Debug("now:%s, length:%d, err:%#v", currentTime, length, err)
log.Debug("now:%s, length:%d, err:%s", currentTime, length, err)
if err == nil {
atomic.AddUint32(&u.readCount, uint32(length))
}
......
......@@ -119,7 +119,7 @@ func (s *server) stop() {
if err = s.server.Shutdown(ctx); err != nil {
// 如果下面内容输出为:server shutdown ctx: context deadline exceeded,
// 则说明有未处理完的active connections。
log.Error("server shutdown ctx:%#v", err)
log.Error("server shutdown ctx:%s error:%s", ctx, err)
}
}
s.server = nil
......@@ -309,7 +309,7 @@ func (s *wsHandler) serveWSRequest(w http.ResponseWriter, r *http.Request) {
conn, err := s.upgrader.Upgrade(w, r, nil)
if err != nil {
log.Warn("upgrader.Upgrader(http.Request{%#v}) = error{%#v}", r, err)
log.Warn("upgrader.Upgrader(http.Request{%#v}) = error{%s}", r, err)
return
}
if conn.RemoteAddr().String() == conn.LocalAddr().String() {
......@@ -321,7 +321,7 @@ func (s *wsHandler) serveWSRequest(w http.ResponseWriter, r *http.Request) {
err = s.newSession(ss)
if err != nil {
conn.Close()
log.Warn("server{%s}.newSession(ss{%#v}) = err {%#v}", s.server.addr, ss, err)
log.Warn("server{%s}.newSession(ss{%#v}) = err {%s}", s.server.addr, ss, err)
return
}
if ss.(*session).maxMsgLen > 0 {
......@@ -355,7 +355,7 @@ func (s *server) runWSEventLoop(newSession NewSessionCallback) {
s.lock.Unlock()
err = server.Serve(s.streamListener)
if err != nil {
log.Error("http.server.Serve(addr{%s}) = err{%#v}", s.addr, err)
log.Error("http.server.Serve(addr{%s}) = err{%s}", s.addr, err)
// panic(err)
}
}()
......@@ -378,7 +378,7 @@ func (s *server) runWSSEventLoop(newSession NewSessionCallback) {
defer s.wg.Done()
if certificate, err = tls.LoadX509KeyPair(s.cert, s.privateKey); err != nil {
panic(fmt.Sprintf("tls.LoadX509KeyPair(cert{%s}, privateKey{%s}) = err{%#v}", s.cert, s.privateKey, err))
panic(fmt.Sprintf("tls.LoadX509KeyPair(cert{%s}, privateKey{%s}) = err{%s}", s.cert, s.privateKey, err))
return
}
config = &tls.Config{
......@@ -391,7 +391,7 @@ func (s *server) runWSSEventLoop(newSession NewSessionCallback) {
if s.caCert != "" {
certPem, err = ioutil.ReadFile(s.caCert)
if err != nil {
panic(fmt.Errorf("ioutil.ReadFile(certFile{%s}) = err{%#v}", s.caCert, err))
panic(fmt.Errorf("ioutil.ReadFile(certFile{%s}) = err{%s}", s.caCert, err))
}
certPool = x509.NewCertPool()
if ok := certPool.AppendCertsFromPEM(certPem); !ok {
......@@ -416,7 +416,7 @@ func (s *server) runWSSEventLoop(newSession NewSessionCallback) {
s.lock.Unlock()
err = server.Serve(tls.NewListener(s.streamListener, config))
if err != nil {
log.Error("http.server.Serve(addr{%s}) = err{%#v}", s.addr, err)
log.Error("http.server.Serve(addr{%s}) = err{%s}", s.addr, err)
panic(err)
}
}()
......@@ -426,7 +426,7 @@ func (s *server) runWSSEventLoop(newSession NewSessionCallback) {
// @newSession: new connection callback
func (s *server) RunEventLoop(newSession NewSessionCallback) {
if err := s.listen(); err != nil {
panic(fmt.Errorf("server.listen() = error:%#v", err))
panic(fmt.Errorf("server.listen() = error:%s", err))
}
switch s.endPointType {
......
......@@ -310,7 +310,7 @@ func (s *session) WritePkg(pkg interface{}, timeout time.Duration) error {
const size = 64 << 10
rBuf := make([]byte, size)
rBuf = rBuf[:runtime.Stack(rBuf, false)]
log.Error("[session.WritePkg] panic session %s: err=%#v\n%s", s.sessionToken(), r, rBuf)
log.Error("[session.WritePkg] panic session %s: err=%s\n%s", s.sessionToken(), r, rBuf)
}
}()
......@@ -423,7 +423,7 @@ func (s *session) handleLoop() {
const size = 64 << 10
rBuf := make([]byte, size)
rBuf = rBuf[:runtime.Stack(rBuf, false)]
log.Error("[session.handleLoop] panic session %s: err=%#v\n%s", s.sessionToken(), r, rBuf)
log.Error("[session.handleLoop] panic session %s: err=%s\n%s", s.sessionToken(), r, rBuf)
}
grNum = atomic.AddInt32(&(s.grNum), -1)
......@@ -471,7 +471,7 @@ LOOP:
case outPkg = <-s.wQ:
if flag {
if err = s.writer.Write(s, outPkg); err != nil {
log.Error("%s, [session.handleLoop] = error{%+v}", s.sessionToken(), err)
log.Error("%s, [session.handleLoop] = error{%s}", s.sessionToken(), err)
s.stop()
flag = false
// break LOOP
......@@ -487,7 +487,7 @@ LOOP:
if wsFlag {
err = wsConn.writePing()
if err != nil {
log.Warn("wsConn.writePing() = error{%#v}", err)
log.Warn("wsConn.writePing() = error{%s}", err)
}
}
s.listener.OnCron(s)
......@@ -509,7 +509,7 @@ func (s *session) handlePackage() {
const size = 64 << 10
rBuf := make([]byte, size)
rBuf = rBuf[:runtime.Stack(rBuf, false)]
log.Error("[session.handlePackage] panic session %s: err=%#v\n%s", s.sessionToken(), r, rBuf)
log.Error("[session.handlePackage] panic session %s: err=%s\n%s", s.sessionToken(), r, rBuf)
}
grNum = atomic.AddInt32(&(s.grNum), -1)
......@@ -517,7 +517,7 @@ func (s *session) handlePackage() {
s.stop()
// if s.errFlag {
if err != nil {
log.Error("%s, [session.handlePackage] error{%#v}", s.sessionToken(), err)
log.Error("%s, [session.handlePackage] error{%s}", s.sessionToken(), err)
s.listener.OnError(s, err)
}
}()
......@@ -572,7 +572,7 @@ func (s *session) handleTCPPackage() error {
if nerr, ok = err.(net.Error); ok && nerr.Timeout() {
break
}
log.Error("%s, [session.conn.read] = error{%#v}", s.sessionToken(), err)
log.Error("%s, [session.conn.read] = error{%s}", s.sessionToken(), err)
// for (Codec)OnErr
// s.errFlag = true
exit = true
......@@ -596,7 +596,7 @@ func (s *session) handleTCPPackage() error {
err = ErrMsgTooLong
}
if err != nil {
log.Warn("%s, [session.handleTCPPackage] = len{%d}, error{%+v}", s.sessionToken(), pkgLen, err)
log.Warn("%s, [session.handleTCPPackage] = len{%d}, error{%s}", s.sessionToken(), pkgLen, err)
// for (Codec)OnErr
// s.errFlag = true
exit = true
......@@ -648,17 +648,17 @@ func (s *session) handleUDPPackage() error {
continue
}
if err != nil {
log.Error("%s, [session.handleUDPPackage] = len{%d}, error{%+v}", s.sessionToken(), bufLen, err)
log.Error("%s, [session.handleUDPPackage] = len{%d}, error{%s}", s.sessionToken(), bufLen, err)
break
}
pkg, pkgLen, err = s.reader.Read(s, buf[:bufLen])
gxlog.CInfo("s.reader.Read() = pkg:%#v, pkgLen:%d, err:%#v", pkg, pkgLen, err)
gxlog.CInfo("s.reader.Read() = pkg:%#v, pkgLen:%d, err:%s", pkg, pkgLen, err)
if err == nil && s.maxMsgLen > 0 && bufLen > int(s.maxMsgLen) {
err = ErrMsgTooLong
}
if err != nil {
log.Warn("%s, [session.handleUDPPackage] = len{%d}, error{%+v}", s.sessionToken(), pkgLen, err)
log.Warn("%s, [session.handleUDPPackage] = len{%d}, error{%s}", s.sessionToken(), pkgLen, err)
continue
}
s.UpdateActive()
......@@ -691,7 +691,7 @@ func (s *session) handleWSPackage() error {
continue
}
if err != nil {
log.Warn("%s, [session.handleWSPackage] = error{%+v}", s.sessionToken(), err)
log.Warn("%s, [session.handleWSPackage] = error{%s}", s.sessionToken(), err)
// s.errFlag = true
return err
}
......@@ -702,7 +702,7 @@ func (s *session) handleWSPackage() error {
err = ErrMsgTooLong
}
if err != nil {
log.Warn("%s, [session.handleWSPackage] = len{%d}, error{%+v}", s.sessionToken(), length, err)
log.Warn("%s, [session.handleWSPackage] = len{%d}, error{%s}", s.sessionToken(), length, err)
continue
}
s.rQ <- unmarshalPkg
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment