Browse Source

improve connection logging

Alan Shreve 12 years ago
parent
commit
f956a32d64
3 changed files with 12 additions and 9 deletions
  1. 3 3
      src/ngrok/client/model.go
  2. 1 1
      src/ngrok/conn/conn.go
  3. 8 5
      src/ngrok/server/control.go

+ 3 - 3
src/ngrok/client/model.go

@@ -339,20 +339,20 @@ func (c *ClientModel) proxy() {
 
 	err = msg.WriteMsg(remoteConn, &msg.RegProxy{ClientId: c.id})
 	if err != nil {
-		log.Error("Failed to write RegProxy: %v", err)
+		remoteConn.Error("Failed to write RegProxy: %v", err)
 		return
 	}
 
 	// wait for the server to ack our register
 	var startPxy msg.StartProxy
 	if err = msg.ReadMsgInto(remoteConn, &startPxy); err != nil {
-		log.Error("Server failed to write StartProxy: %v", err)
+		remoteConn.Error("Server failed to write StartProxy: %v", err)
 		return
 	}
 
 	tunnel, ok := c.tunnels[startPxy.Url]
 	if !ok {
-		c.Error("Couldn't find tunnel for proxy: %s", startPxy.Url)
+		remoteConn.Error("Couldn't find tunnel for proxy: %s", startPxy.Url)
 		return
 	}
 

+ 1 - 1
src/ngrok/conn/conn.go

@@ -202,7 +202,7 @@ func Join(c Conn, c2 Conn) (int64, int64) {
 		if err != nil {
 			from.Warn("Copied %d bytes to %s before failing with error %v", *bytesCopied, to.Id(), err)
 		} else {
-			from.Debug("Copied %d bytes from to %s", *bytesCopied, to.Id())
+			from.Debug("Copied %d bytes to %s", *bytesCopied, to.Id())
 		}
 	}
 

+ 8 - 5
src/ngrok/server/control.go

@@ -90,6 +90,10 @@ func NewControl(ctlConn conn.Conn, authMsg *msg.Auth) {
 		}
 	}
 
+	// set logging prefix
+	ctlConn.SetType("ctl")
+	ctlConn.AddLogPrefix(c.id)
+
 	if authMsg.Version != version.Proto {
 		failAuth(fmt.Errorf("Incompatible versions. Server %s, client %s. Download a new version at http://ngrok.com", version.MajorMinor(), authMsg.Version))
 		return
@@ -100,9 +104,6 @@ func NewControl(ctlConn conn.Conn, authMsg *msg.Auth) {
 		replaced.shutdown.WaitComplete()
 	}
 
-	// set logging prefix
-	ctlConn.SetType("ctl")
-
 	// start the writer first so that the follow messages get sent
 	go c.writer()
 
@@ -289,11 +290,13 @@ func (c *Control) stopper() {
 }
 
 func (c *Control) RegisterProxy(conn conn.Conn) {
+	conn.AddLogPrefix(c.id)
+
 	select {
 	case c.proxies <- conn:
-		c.conn.Info("Registered proxy connection %s", conn.Id())
+		conn.Info("Registered")
 	default:
-		// c.proxies buffer is full, discard this one
+		conn.Info("Proxies buffer is full, discarding.")
 		conn.Close()
 	}
 }