Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
Clean up logging
Browse files Browse the repository at this point in the history
Ensure that the server only logs in exceptional cases and prefixes
each log line with the package name.

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
  • Loading branch information
titanous committed Jul 4, 2017
1 parent a2015b1 commit e0a698a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
4 changes: 2 additions & 2 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (ch *channel) ReadFcall(ctx context.Context, fcall *Fcall) error {
}

if err := ch.conn.SetReadDeadline(deadline); err != nil {
log.Printf("transport: error setting read deadline on %v: %v", ch.conn.RemoteAddr(), err)
log.Printf("p9p: transport: error setting read deadline on %v: %v", ch.conn.RemoteAddr(), err)
}

n, err := readmsg(ch.brd, ch.rdbuf)
Expand Down Expand Up @@ -184,7 +184,7 @@ func (ch *channel) WriteFcall(ctx context.Context, fcall *Fcall) error {
}

if err := ch.conn.SetWriteDeadline(deadline); err != nil {
log.Printf("transport: error setting read deadline on %v: %v", ch.conn.RemoteAddr(), err)
log.Printf("p9p: transport: error setting read deadline on %v: %v", ch.conn.RemoteAddr(), err)
}

if err := ch.maybeTruncate(fcall); err != nil {
Expand Down
5 changes: 1 addition & 4 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/binary"
"fmt"
"io"
"log"
"reflect"
"strings"
"time"
Expand Down Expand Up @@ -330,9 +329,7 @@ func (d *decoder) decode(vs ...interface{}) error {

b := make([]byte, ll)
// must consume entire dir entry.
n, err := io.ReadFull(d.rd, b)
if err != nil {
log.Println("dir readfull failed:", err, ll, n)
if _, err := io.ReadFull(d.rd, b); err != nil {
return err
}

Expand Down
6 changes: 1 addition & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (c *conn) serve() error {
go c.read(requests)
go c.write(responses)

log.Println("server.run()")
for {
select {
case req := <-requests:
Expand All @@ -97,8 +96,6 @@ func (c *conn) serve() error {

switch msg := req.Message.(type) {
case MessageTflush:
log.Println("server: flushing message", msg.Oldtag)

var resp *Fcall
// check if we have actually know about the requested flush
active, ok := tags[msg.Oldtag]
Expand Down Expand Up @@ -167,7 +164,6 @@ func (c *conn) serve() error {
// the context was canceled for some reason, perhaps timeout or
// due to a flush call. We treat this as a condition where a
// response should not be sent.
log.Println("canceled", resp, active.ctx.Err())
}
delete(tags, resp.Tag)
case <-c.ctx.Done():
Expand Down Expand Up @@ -222,7 +218,7 @@ func (c *conn) write(responses chan *Fcall) {
// TODO(stevvooe): A full idle timeout on the
// connection should be enforced here. We log here,
// since this is less common.
log.Printf("9p server: temporary error writing fcall: %v", err)
log.Printf("p9p: temporary error writing fcall: %v", err)
continue
}
}
Expand Down
5 changes: 1 addition & 4 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func allocateTag(r *fcallRequest, m map[Tag]*fcallRequest, hint Tag) (Tag, error
// handle takes messages off the wire and wakes up the waiting tag call.
func (t *transport) handle() {
defer func() {
log.Println("exited handle loop")
close(t.closed)
}()

Expand All @@ -143,7 +142,6 @@ func (t *transport) handle() {
// loop to read messages off of the connection
go func() {
defer func() {
log.Println("exited read loop")
t.close() // single main loop
}()
loop:
Expand All @@ -161,15 +159,14 @@ func (t *transport) handle() {
}
}

log.Println("fatal error reading msg:", err)
log.Println("p9p: fatal error reading msg:", err)
return
}

select {
case <-t.ctx.Done():
return
case <-t.closed:
log.Println("transport closed")
return
case responses <- fcall:
}
Expand Down

0 comments on commit e0a698a

Please sign in to comment.