Skip to content

Commit

Permalink
Further refactoring: Move to new logging style but still with stdlog.
Browse files Browse the repository at this point in the history
  • Loading branch information
numbleroot committed May 11, 2017
1 parent e204b84 commit a35f742
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 54 deletions.
16 changes: 8 additions & 8 deletions imap/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ func (c *Connection) InternalSend(inc bool, text string) error {
// Test if connection is still healthy.
_, err := conn.Write([]byte("> ping <\r\n"))
if err != nil {
return fmt.Errorf("sending ping to node '%s' failed: %s", conn.RemoteAddr().String(), err.Error())
return fmt.Errorf("sending ping to node '%s' failed: %v", conn.RemoteAddr().String(), err)
}

// Write message to TLS connections.
_, err = fmt.Fprintf(conn, "%s\r\n", text)
for err != nil {

stdlog.Printf("[imap.InternalSend] Sending to node '%s' failed, trying to recover...\n", conn.RemoteAddr())
stdlog.Printf("[imap.InternalSend] Sending to node '%s' failed, trying to recover...", conn.RemoteAddr())

// Define what IP and port of remote node look like.
remoteAddr := conn.RemoteAddr().String()
Expand All @@ -119,7 +119,7 @@ func (c *Connection) InternalSend(inc bool, text string) error {
// Reestablish TLS connection to remote node.
conn, err = comm.ReliableConnect(remoteAddr, c.IntlTLSConfig, c.IntlConnRetry)
if err != nil {
return fmt.Errorf("failed to reestablish connection with '%s': %s", remoteAddr, err.Error())
return fmt.Errorf("failed to reestablish connection with '%s': %v", remoteAddr, err)
}

// Save context to connection.
Expand All @@ -133,16 +133,16 @@ func (c *Connection) InternalSend(inc bool, text string) error {
// Inform remote node about which session was active.
err = c.SignalSessionStart(false)
if err != nil {
return fmt.Errorf("signalling session to remote node failed with: %s", err.Error())
return fmt.Errorf("signalling session to remote node failed with: %v", err)
}
}

stdlog.Printf("[imap.InternalSend] Reconnected to '%s'.\n", remoteAddr)
stdlog.Printf("[imap.InternalSend] Reconnected to '%s'.", remoteAddr)

// Resend message to remote node.
_, err = fmt.Fprintf(conn, "%s\r\n", text)
} else {
return fmt.Errorf("failed to send message to remote node '%s': %s", remoteAddr, err.Error())
return fmt.Errorf("failed to send message to remote node '%s': %v", remoteAddr, err)
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ func (c *Connection) Receive(inc bool) (string, error) {
if err != nil {

if err.Error() == "EOF" {
stdlog.Printf("[imap.Receive] Node at '%s' disconnected.\n", conn.RemoteAddr().String())
stdlog.Printf("[imap.Receive] Node at '%s' disconnected.", conn.RemoteAddr().String())
}

break
Expand Down Expand Up @@ -320,7 +320,7 @@ func (c *Connection) Terminate() error {
func (c *Connection) Error(msg string, err error) {

// Log error.
stdlog.Printf("%s: %s. Terminating connection to %s.\n", msg, err.Error(), c.IncConn.RemoteAddr().String())
stdlog.Printf("%s: %v. Terminating connection to %s.", msg, err, c.IncConn.RemoteAddr().String())

// Terminate connection.
err = c.Terminate()
Expand Down
4 changes: 2 additions & 2 deletions imap/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func InitDistributor(logger log.Logger, config *config.Config, auth PlainAuthent
// Start to listen for incoming public connections on defined IP and port.
distr.Socket, err = tls.Listen("tcp", fmt.Sprintf("%s:%s", config.Distributor.ListenIP, config.Distributor.Port), publicTLSConfig)
if err != nil {
return nil, fmt.Errorf("[imap.InitDistributor] Listening for public TLS connections failed with: %s\n", err.Error())
return nil, fmt.Errorf("[imap.InitDistributor] Listening for public TLS connections failed with: %v", err)
}

level.Info(logger).Log(
Expand All @@ -100,7 +100,7 @@ func (distr *Distributor) Run() error {
// Accept request or fail on error.
conn, err := distr.Socket.Accept()
if err != nil {
return fmt.Errorf("[imap.Run] Accepting incoming request at distributor failed with: %s\n", err.Error())
return fmt.Errorf("[imap.Run] Accepting incoming request at distributor failed with: %v", err)
}

// Dispatch into own goroutine.
Expand Down
Loading

0 comments on commit a35f742

Please sign in to comment.