Merge "x/ref/examples: use context-based logging and logger.Global()"
diff --git a/examples/rps/internal/common.go b/examples/rps/internal/common.go
index 5ecb143..2d15a8e 100644
--- a/examples/rps/internal/common.go
+++ b/examples/rps/internal/common.go
@@ -18,19 +18,20 @@
 	"v.io/v23"
 	"v.io/v23/context"
 	"v.io/v23/naming"
-	"v.io/x/lib/vlog"
+
 	"v.io/x/ref/examples/rps"
+	"v.io/x/ref/internal/logger"
 )
 
 // CreateName creates a name using the username and hostname.
 func CreateName() string {
 	hostname, err := os.Hostname()
 	if err != nil {
-		vlog.Fatalf("os.Hostname failed: %v", err)
+		logger.Global().Fatalf("os.Hostname failed: %v", err)
 	}
 	u, err := user.Current()
 	if err != nil {
-		vlog.Fatalf("user.Current failed: %v", err)
+		logger.Global().Fatalf("user.Current failed: %v", err)
 	}
 	return u.Username + "@" + hostname
 }
@@ -74,19 +75,19 @@
 	ns := v23.GetNamespace(ctx)
 	c, err := ns.Glob(ctx, "rps/"+t+"/*")
 	if err != nil {
-		vlog.Infof("mt.Glob failed: %v", err)
+		ctx.Infof("mt.Glob failed: %v", err)
 		return nil, err
 	}
 	var servers []string
 	for e := range c {
 		switch v := e.(type) {
 		case *naming.GlobReplyError:
-			vlog.VI(1).Infof("findAll(%q) error for %q: %v", t, v.Value.Name, v.Value.Error)
+			ctx.VI(1).Infof("findAll(%q) error for %q: %v", t, v.Value.Name, v.Value.Error)
 		case *naming.GlobReplyEntry:
 			servers = append(servers, v.Value.Name)
 		}
 	}
-	vlog.VI(1).Infof("findAll(%q) elapsed: %s", t, time.Now().Sub(start))
+	ctx.VI(1).Infof("findAll(%q) elapsed: %s", t, time.Now().Sub(start))
 	return servers, nil
 }
 
diff --git a/examples/rps/rpsbot/impl.go b/examples/rps/rpsbot/impl.go
index 9c95d2c..3223ac8 100644
--- a/examples/rps/rpsbot/impl.go
+++ b/examples/rps/rpsbot/impl.go
@@ -11,7 +11,6 @@
 	"v.io/v23/rpc"
 	"v.io/v23/security"
 	"v.io/v23/vtrace"
-	"v.io/x/lib/vlog"
 	"v.io/x/ref/examples/rps"
 )
 
@@ -40,9 +39,9 @@
 }
 
 func (r *RPS) CreateGame(ctx *context.T, call rpc.ServerCall, opts rps.GameOptions) (rps.GameId, error) {
-	if vlog.V(1) {
+	if ctx.V(1) {
 		b, _ := security.RemoteBlessingNames(ctx, call.Security())
-		vlog.Infof("CreateGame %+v from %v", opts, b)
+		ctx.Infof("CreateGame %+v from %v", opts, b)
 	}
 	names := security.LocalBlessingNames(ctx, call.Security())
 	if len(names) == 0 {
@@ -53,7 +52,7 @@
 
 func (r *RPS) Play(ctx *context.T, call rps.JudgePlayServerCall, id rps.GameId) (rps.PlayResult, error) {
 	names, _ := security.RemoteBlessingNames(ctx, call.Security())
-	vlog.VI(1).Infof("Play %+v from %v", id, names)
+	ctx.VI(1).Infof("Play %+v from %v", id, names)
 	if len(names) == 0 {
 		return rps.PlayResult{}, errors.New("no names provided for context")
 	}
@@ -62,13 +61,13 @@
 
 func (r *RPS) Challenge(ctx *context.T, call rpc.ServerCall, address string, id rps.GameId, opts rps.GameOptions) error {
 	b, _ := security.RemoteBlessingNames(ctx, call.Security())
-	vlog.VI(1).Infof("Challenge (%q, %+v, %+v) from %v", address, id, opts, b)
+	ctx.VI(1).Infof("Challenge (%q, %+v, %+v) from %v", address, id, opts, b)
 	newctx, _ := vtrace.WithNewTrace(r.ctx)
 	return r.player.challenge(newctx, address, id, opts)
 }
 
 func (r *RPS) Record(ctx *context.T, call rpc.ServerCall, score rps.ScoreCard) error {
 	b, _ := security.RemoteBlessingNames(ctx, call.Security())
-	vlog.VI(1).Infof("Record (%+v) from %v", score, b)
+	ctx.VI(1).Infof("Record (%+v) from %v", score, b)
 	return r.scoreKeeper.Record(ctx, call, score)
 }
diff --git a/examples/rps/rpsbot/judge.go b/examples/rps/rpsbot/judge.go
index cd3bdd5..f63e15f 100644
--- a/examples/rps/rpsbot/judge.go
+++ b/examples/rps/rpsbot/judge.go
@@ -12,9 +12,10 @@
 	"time"
 
 	"v.io/v23/context"
-	"v.io/x/lib/vlog"
+
 	"v.io/x/ref/examples/rps"
 	"v.io/x/ref/examples/rps/internal"
+	"v.io/x/ref/internal/logger"
 	"v.io/x/ref/lib/stats"
 	"v.io/x/ref/lib/stats/counter"
 )
@@ -85,7 +86,7 @@
 
 // createGame handles a request to create a new game.
 func (j *Judge) createGame(ownName string, opts rps.GameOptions) (rps.GameId, error) {
-	vlog.VI(1).Infof("createGame called")
+	logger.Global().VI(1).Infof("createGame called")
 	score := rps.ScoreCard{Opts: opts, Judge: ownName}
 	now := time.Now()
 	id := rps.GameId{Id: strconv.FormatInt(now.UnixNano(), 16)}
@@ -94,7 +95,7 @@
 	defer j.lock.Unlock()
 	for k, v := range j.games {
 		if now.Sub(v.startTime) > 1*time.Hour {
-			vlog.Infof("Removing stale game ID %v", k)
+			logger.Global().Infof("Removing stale game ID %v", k)
 			delete(j.games, k)
 		}
 	}
@@ -114,7 +115,7 @@
 
 // play interacts with a player for the duration of a game.
 func (j *Judge) play(ctx *context.T, call rps.JudgePlayServerCall, name string, id rps.GameId) (rps.PlayResult, error) {
-	vlog.VI(1).Infof("play from %q for %v", name, id)
+	ctx.VI(1).Infof("play from %q for %v", name, id)
 	nilResult := rps.PlayResult{}
 
 	pIn, pOut, s, err := j.gameChannels(id)
@@ -125,7 +126,7 @@
 	if err != nil {
 		return nilResult, err
 	}
-	vlog.VI(1).Infof("This is player %d", playerNum)
+	ctx.VI(1).Infof("This is player %d", playerNum)
 
 	// Send all user input to the player input channel.
 	stopRead := make(chan struct{})
@@ -151,7 +152,7 @@
 		defer close(writeDone)
 		for packet := range pOut[playerNum-1] {
 			if err := call.SendStream().Send(packet); err != nil {
-				vlog.Infof("error sending to player stream: %v", err)
+				ctx.Infof("error sending to player stream: %v", err)
 			}
 		}
 	}()
@@ -231,7 +232,7 @@
 	defer cancel()
 	keepers, err := internal.FindScoreKeepers(scoreCtx)
 	if err != nil || len(keepers) == 0 {
-		vlog.Infof("No score keepers: %v", err)
+		ctx.Infof("No score keepers: %v", err)
 		return
 	}
 	var wg sync.WaitGroup
@@ -267,11 +268,11 @@
 			}
 			round.Moves[in.player-1] = move
 		default:
-			vlog.Infof("unexpected message type: %T", in.action)
+			logger.Global().Infof("unexpected message type: %T", in.action)
 		}
 	}
 	round.Winner, round.Comment = j.compareMoves(round.Moves[0], round.Moves[1])
-	vlog.VI(1).Infof("Player 1 played %q. Player 2 played %q. Winner: %d %s", round.Moves[0], round.Moves[1], round.Winner, round.Comment)
+	logger.Global().VI(1).Infof("Player 1 played %q. Player 2 played %q. Winner: %d %s", round.Moves[0], round.Moves[1], round.Winner, round.Comment)
 
 	action = rps.JudgeActionRoundResult{round}
 	for _, p := range info.playerOut {
@@ -311,7 +312,7 @@
 	defer wg.Done()
 	k := rps.RockPaperScissorsClient(address)
 	if err := k.Record(ctx, score); err != nil {
-		vlog.Infof("Record: %v", err)
+		logger.Global().Infof("Record: %v", err)
 		return err
 	}
 	return nil
diff --git a/examples/rps/rpsbot/main.go b/examples/rps/rpsbot/main.go
index 4fbcaab..fff0e7a 100644
--- a/examples/rps/rpsbot/main.go
+++ b/examples/rps/rpsbot/main.go
@@ -12,10 +12,11 @@
 	"math/rand"
 	"time"
 
+	"v.io/x/lib/cmdline"
+
 	"v.io/v23"
 	"v.io/v23/context"
-	"v.io/x/lib/cmdline"
-	"v.io/x/lib/vlog"
+
 	"v.io/x/ref/examples/rps"
 	"v.io/x/ref/examples/rps/internal"
 	"v.io/x/ref/lib/signals"
@@ -79,7 +80,7 @@
 			return fmt.Errorf("(%v) failed: %v", n, err)
 		}
 	}
-	vlog.Infof("Listening on endpoint %s (published as %v)", eps, names)
+	ctx.Infof("Listening on endpoint %s (published as %v)", eps, names)
 
 	go initiateGames(ctx, rpsService)
 	<-signals.ShutdownOnSignals(ctx)
@@ -89,7 +90,7 @@
 func initiateGames(ctx *context.T, rpsService *RPS) {
 	for i := 0; i < numGames || numGames == -1; i++ {
 		if err := rpsService.Player().InitiateGame(ctx); err != nil {
-			vlog.Infof("Failed to initiate game: %v", err)
+			ctx.Infof("Failed to initiate game: %v", err)
 		}
 		time.Sleep(5 * time.Second)
 	}
diff --git a/examples/rps/rpsbot/player.go b/examples/rps/rpsbot/player.go
index 40a7720..31ad9b0 100644
--- a/examples/rps/rpsbot/player.go
+++ b/examples/rps/rpsbot/player.go
@@ -9,7 +9,7 @@
 	"time"
 
 	"v.io/v23/context"
-	"v.io/x/lib/vlog"
+
 	"v.io/x/ref/examples/rps"
 	"v.io/x/ref/examples/rps/internal"
 	"v.io/x/ref/lib/stats"
@@ -46,37 +46,37 @@
 func (p *Player) InitiateGame(ctx *context.T) error {
 	judge, err := internal.FindJudge(ctx)
 	if err != nil {
-		vlog.Infof("FindJudge: %v", err)
+		ctx.Infof("FindJudge: %v", err)
 		return err
 	}
 	gameID, gameOpts, err := p.createGame(ctx, judge)
 	if err != nil {
-		vlog.Infof("createGame: %v", err)
+		ctx.Infof("createGame: %v", err)
 		return err
 	}
-	vlog.VI(1).Infof("Created gameID %q on %q", gameID, judge)
+	ctx.VI(1).Infof("Created gameID %q on %q", gameID, judge)
 
 	for {
 		opponent, err := internal.FindPlayer(ctx)
 		if err != nil {
-			vlog.Infof("FindPlayer: %v", err)
+			ctx.Infof("FindPlayer: %v", err)
 			return err
 		}
-		vlog.VI(1).Infof("chosen opponent is %q", opponent)
+		ctx.VI(1).Infof("chosen opponent is %q", opponent)
 		if err = p.sendChallenge(ctx, opponent, judge, gameID, gameOpts); err == nil {
 			break
 		}
-		vlog.Infof("sendChallenge: %v", err)
+		ctx.Infof("sendChallenge: %v", err)
 	}
 	result, err := p.playGame(ctx, judge, gameID)
 	if err != nil {
-		vlog.Infof("playGame: %v", err)
+		ctx.Infof("playGame: %v", err)
 		return err
 	}
 	if result.YouWon {
-		vlog.VI(1).Info("Game result: I won! :)")
+		ctx.VI(1).Info("Game result: I won! :)")
 	} else {
-		vlog.VI(1).Info("Game result: I lost :(")
+		ctx.VI(1).Info("Game result: I lost :(")
 	}
 	return nil
 }
@@ -101,7 +101,7 @@
 // challenge receives an incoming challenge and starts to play a new game.
 // Note that the new game will occur in a new context.
 func (p *Player) challenge(ctx *context.T, judge string, gameID rps.GameId, _ rps.GameOptions) error {
-	vlog.VI(1).Infof("challenge received: %s %v", judge, gameID)
+	ctx.VI(1).Infof("challenge received: %s %v", judge, gameID)
 	go p.playGame(ctx, judge, gameID)
 	return nil
 }
@@ -124,31 +124,31 @@
 		in := rStream.Value()
 		switch v := in.(type) {
 		case rps.JudgeActionPlayerNum:
-			vlog.VI(1).Infof("I'm player %d", v.Value)
+			outer.VI(1).Infof("I'm player %d", v.Value)
 		case rps.JudgeActionOpponentName:
-			vlog.VI(1).Infof("My opponent is %q", v.Value)
+			outer.VI(1).Infof("My opponent is %q", v.Value)
 		case rps.JudgeActionMoveOptions:
 			opts := v.Value
 			n := rand.Intn(len(opts))
-			vlog.VI(1).Infof("My turn to play. Picked %q from %v", opts[n], opts)
+			outer.VI(1).Infof("My turn to play. Picked %q from %v", opts[n], opts)
 			if err := sender.Send(rps.PlayerActionMove{opts[n]}); err != nil {
 				return rps.PlayResult{}, err
 			}
 		case rps.JudgeActionRoundResult:
 			rr := v.Value
-			vlog.VI(1).Infof("Player 1 played %q. Player 2 played %q. Winner: %v %s",
+			outer.VI(1).Infof("Player 1 played %q. Player 2 played %q. Winner: %v %s",
 				rr.Moves[0], rr.Moves[1], rr.Winner, rr.Comment)
 		case rps.JudgeActionScore:
-			vlog.VI(1).Infof("Score card: %s", internal.FormatScoreCard(v.Value))
+			outer.VI(1).Infof("Score card: %s", internal.FormatScoreCard(v.Value))
 		default:
-			vlog.Infof("unexpected message type: %T", in)
+			outer.Infof("unexpected message type: %T", in)
 		}
 	}
 
 	if err := rStream.Err(); err != nil {
-		vlog.Infof("stream error: %v", err)
+		outer.Infof("stream error: %v", err)
 	} else {
-		vlog.VI(1).Infof("Game Ended")
+		outer.VI(1).Infof("Game Ended")
 	}
 	result, err := game.Finish()
 	p.gamesPlayed.Incr(1)
diff --git a/examples/rps/rpsbot/scorekeeper.go b/examples/rps/rpsbot/scorekeeper.go
index 4cd9f93..900ec24 100644
--- a/examples/rps/rpsbot/scorekeeper.go
+++ b/examples/rps/rpsbot/scorekeeper.go
@@ -8,7 +8,6 @@
 	"v.io/v23/context"
 	"v.io/v23/rpc"
 	"v.io/v23/security"
-	"v.io/x/lib/vlog"
 	"v.io/x/ref/examples/rps"
 	"v.io/x/ref/examples/rps/internal"
 	"v.io/x/ref/lib/stats"
@@ -31,8 +30,8 @@
 
 func (k *ScoreKeeper) Record(ctx *context.T, call rpc.ServerCall, score rps.ScoreCard) error {
 	b, _ := security.RemoteBlessingNames(ctx, call.Security())
-	vlog.VI(1).Infof("Received ScoreCard from %v:", b)
-	vlog.VI(1).Info(internal.FormatScoreCard(score))
+	ctx.VI(1).Infof("Received ScoreCard from %v:", b)
+	ctx.VI(1).Info(internal.FormatScoreCard(score))
 	k.numRecords.Incr(1)
 	return nil
 }
diff --git a/examples/rps/rpsplayer/main.go b/examples/rps/rpsplayer/main.go
index f24515b..dae9a77 100644
--- a/examples/rps/rpsplayer/main.go
+++ b/examples/rps/rpsplayer/main.go
@@ -15,17 +15,19 @@
 	"sync"
 	"time"
 
+	"v.io/x/lib/cmdline"
+	"v.io/x/ref/lib/v23cmd"
+
 	"v.io/v23"
 	"v.io/v23/context"
 	"v.io/v23/naming"
 	"v.io/v23/rpc"
 	"v.io/v23/security"
 	"v.io/v23/vtrace"
-	"v.io/x/lib/cmdline"
-	"v.io/x/lib/vlog"
+
 	"v.io/x/ref/examples/rps"
 	"v.io/x/ref/examples/rps/internal"
-	"v.io/x/ref/lib/v23cmd"
+	"v.io/x/ref/internal/logger"
 
 	_ "v.io/x/ref/runtime/factories/roaming"
 )
@@ -91,7 +93,7 @@
 
 func (i *impl) Challenge(ctx *context.T, call rpc.ServerCall, address string, id rps.GameId, opts rps.GameOptions) error {
 	remote, _ := security.RemoteBlessingNames(ctx, call.Security())
-	vlog.VI(1).Infof("Challenge (%q, %+v) from %v", address, id, remote)
+	ctx.VI(1).Infof("Challenge (%q, %+v) from %v", address, id, remote)
 	// When setDecline(true) returns, future challenges will be declined.
 	// Whether the current challenge should be considered depends on the
 	// previous state. If 'decline' was already true, we need to decline
@@ -124,22 +126,22 @@
 func recvChallenge(ctx *context.T) gameChallenge {
 	server, err := v23.NewServer(ctx)
 	if err != nil {
-		vlog.Fatalf("NewServer failed: %v", err)
+		ctx.Fatalf("NewServer failed: %v", err)
 	}
 	ch := make(chan gameChallenge)
 
 	listenSpec := v23.GetListenSpec(ctx)
 	ep, err := server.Listen(listenSpec)
 	if err != nil {
-		vlog.Fatalf("Listen(%v) failed: %v", listenSpec, err)
+		ctx.Fatalf("Listen(%v) failed: %v", listenSpec, err)
 	}
 	if name == "" {
 		name = internal.CreateName()
 	}
 	if err := server.Serve(fmt.Sprintf("rps/player/%s", name), rps.PlayerServer(&impl{ch: ch}), internal.NewAuthorizer(aclFile)); err != nil {
-		vlog.Fatalf("Serve failed: %v", err)
+		ctx.Fatalf("Serve failed: %v", err)
 	}
-	vlog.Infof("Listening on endpoint /%s", ep)
+	ctx.Infof("Listening on endpoint /%s", ep)
 	result := <-ch
 	server.Stop()
 	return result
@@ -174,7 +176,7 @@
 
 	gameID, err := createGame(ctx, judges[j], gameOpts)
 	if err != nil {
-		vlog.Infof("createGame: %v", err)
+		ctx.Infof("createGame: %v", err)
 		return err
 	}
 	for {
@@ -189,7 +191,7 @@
 	fmt.Println("Joining the game...")
 
 	if _, err = playGame(ctx, judges[j], gameID); err != nil {
-		vlog.Infof("playGame: %v", err)
+		ctx.Infof("playGame: %v", err)
 		return err
 	}
 	return nil
@@ -227,7 +229,7 @@
 		case rps.JudgeActionRoundResult:
 			rr := v.Value
 			if playerNum != 1 && playerNum != 2 {
-				vlog.Fatalf("invalid playerNum: %d", playerNum)
+				ctx.Fatalf("invalid playerNum: %d", playerNum)
 			}
 			fmt.Printf("You played %q\n", rr.Moves[playerNum-1])
 			fmt.Printf("Your opponent played %q\n", rr.Moves[2-playerNum])
@@ -261,13 +263,13 @@
 				fmt.Println("You lost! :(")
 			}
 		default:
-			vlog.Infof("unexpected message type: %T", in)
+			outer.Infof("unexpected message type: %T", in)
 		}
 	}
 	if err := rStream.Err(); err == nil {
 		fmt.Println("Game Ended")
 	} else {
-		vlog.Infof("stream error: %v", err)
+		outer.Infof("stream error: %v", err)
 	}
 
 	return game.Finish()
@@ -275,7 +277,7 @@
 
 func selectOne(choices []string) (choice int) {
 	if len(choices) == 0 {
-		vlog.Fatal("No options to choose from!")
+		logger.Global().Fatal("No options to choose from!")
 	}
 	fmt.Println()
 	for i, x := range choices {
@@ -303,7 +305,7 @@
 	var result []string
 	c, err := ns.Glob(ctx, "rps/"+t+"/*")
 	if err != nil {
-		vlog.Infof("ns.Glob failed: %v", err)
+		ctx.Infof("ns.Glob failed: %v", err)
 		out <- result
 		return
 	}
@@ -317,7 +319,7 @@
 		}
 	}
 	if len(result) == 0 {
-		vlog.Infof("found no %ss", t)
+		ctx.Infof("found no %ss", t)
 		out <- result
 		return
 	}
diff --git a/examples/rps/rpsscorekeeper/main.go b/examples/rps/rpsscorekeeper/main.go
index 3ec7224..8deb4bf 100644
--- a/examples/rps/rpsscorekeeper/main.go
+++ b/examples/rps/rpsscorekeeper/main.go
@@ -11,16 +11,16 @@
 	"fmt"
 	"os"
 
+	"v.io/x/lib/cmdline"
+
 	"v.io/v23"
 	"v.io/v23/context"
 	"v.io/v23/rpc"
 	"v.io/v23/security"
-	"v.io/x/lib/cmdline"
-	"v.io/x/lib/vlog"
+
 	"v.io/x/ref/examples/rps"
 	"v.io/x/ref/examples/rps/internal"
 	"v.io/x/ref/lib/v23cmd"
-
 	_ "v.io/x/ref/runtime/factories/roaming"
 )
 
@@ -49,7 +49,7 @@
 
 func (i *impl) Record(ctx *context.T, call rpc.ServerCall, score rps.ScoreCard) error {
 	b, _ := security.RemoteBlessingNames(ctx, call.Security())
-	vlog.VI(1).Infof("Record (%+v) from %v", score, b)
+	ctx.VI(1).Infof("Record (%+v) from %v", score, b)
 	i.ch <- score
 	return nil
 }
@@ -76,7 +76,7 @@
 	if err := server.Serve(fmt.Sprintf("rps/scorekeeper/%s", hostname), rps.ScoreKeeperServer(rpsService), internal.NewAuthorizer(aclFile)); err != nil {
 		return fmt.Errorf("Serve failed: %v", err)
 	}
-	vlog.Infof("Listening on endpoint /%s", ep)
+	ctx.Infof("Listening on endpoint /%s", ep)
 
 	for score := range ch {
 		fmt.Print("======================\n", internal.FormatScoreCard(score))
diff --git a/examples/tunnel/internal/terminal.go b/examples/tunnel/internal/terminal.go
index db08dba..d8ca950 100644
--- a/examples/tunnel/internal/terminal.go
+++ b/examples/tunnel/internal/terminal.go
@@ -13,7 +13,7 @@
 	"syscall"
 	"unsafe"
 
-	"v.io/x/lib/vlog"
+	"v.io/x/ref/internal/logger"
 )
 
 // Winsize defines the window size used by ioctl TIOCGWINSZ and TIOCSWINSZ.
@@ -21,12 +21,11 @@
 	Row    uint16
 	Col    uint16
 	Xpixel uint16
-	Ypixel uint16
 }
 
 // SetWindowSize sets the terminal's window size.
 func SetWindowSize(fd uintptr, ws Winsize) error {
-	vlog.Infof("Setting window size: %v", ws)
+	logger.Global().Infof("Setting window size: %v", ws)
 	ret, _, _ := syscall.Syscall(
 		syscall.SYS_IOCTL,
 		fd,
@@ -60,7 +59,7 @@
 	var savedBytes []byte
 	var err error
 	if savedBytes, err = exec.Command("stty", "-F", "/dev/tty", "-g").Output(); err != nil {
-		vlog.Infof("Failed to save terminal settings: %q (%v)", savedBytes, err)
+		logger.Global().Infof("Failed to save terminal settings: %q (%v)", savedBytes, err)
 	}
 	saved := strings.TrimSpace(string(savedBytes))
 
@@ -86,7 +85,7 @@
 		"-iexten",
 	}
 	if out, err := exec.Command("stty", args...).CombinedOutput(); err != nil {
-		vlog.Infof("stty failed (%v) (%q)", err, out)
+		logger.Global().Infof("stty failed (%v) (%q)", err, out)
 	}
 
 	return string(saved)
@@ -100,6 +99,6 @@
 		saved,
 	}
 	if out, err := exec.Command("stty", args...).CombinedOutput(); err != nil {
-		vlog.Infof("stty failed (%v) (%q)", err, out)
+		logger.Global().Infof("stty failed (%v) (%q)", err, out)
 	}
 }
diff --git a/examples/tunnel/tunneld/impl.go b/examples/tunnel/tunneld/impl.go
index 7389974..020707e 100644
--- a/examples/tunnel/tunneld/impl.go
+++ b/examples/tunnel/tunneld/impl.go
@@ -17,8 +17,9 @@
 	"syscall"
 
 	"v.io/v23/context"
+	"v.io/v23/logging"
 	"v.io/v23/security"
-	"v.io/x/lib/vlog"
+
 	"v.io/x/ref/examples/tunnel"
 	"v.io/x/ref/examples/tunnel/internal"
 )
@@ -36,15 +37,15 @@
 	}
 	b, _ := security.RemoteBlessingNames(ctx, call.Security())
 	name := fmt.Sprintf("RemoteBlessings:%v LocalAddr:%v RemoteAddr:%v", b, conn.LocalAddr(), conn.RemoteAddr())
-	vlog.Infof("TUNNEL START: %v", name)
+	ctx.Infof("TUNNEL START: %v", name)
 	err = internal.Forward(conn, call.SendStream(), call.RecvStream())
-	vlog.Infof("TUNNEL END  : %v (%v)", name, err)
+	ctx.Infof("TUNNEL END  : %v (%v)", name, err)
 	return err
 }
 
 func (t *T) Shell(ctx *context.T, call tunnel.TunnelShellServerCall, command string, shellOpts tunnel.ShellOpts) (int32, error) {
 	b, _ := security.RemoteBlessingNames(ctx, call.Security())
-	vlog.Infof("SHELL START for %v: %q", b, command)
+	ctx.Infof("SHELL START for %v: %q", b, command)
 	shell, err := findShell()
 	if err != nil {
 		return nonShellErrorCode, err
@@ -53,7 +54,7 @@
 	// An empty command means that we need an interactive shell.
 	if len(command) == 0 {
 		c = exec.Command(shell, "-i")
-		sendMotd(call)
+		sendMotd(ctx, call)
 	} else {
 		c = exec.Command(shell, "-c", command)
 	}
@@ -63,10 +64,10 @@
 		fmt.Sprintf("PATH=%s", os.Getenv("PATH")),
 	}
 	c.Env = append(c.Env, shellOpts.Environment...)
-	vlog.Infof("Shell environment: %v", c.Env)
+	ctx.Infof("Shell environment: %v", c.Env)
 
 	c.Dir = os.Getenv("HOME")
-	vlog.Infof("Shell CWD: %v", c.Dir)
+	ctx.Infof("Shell CWD: %v", c.Dir)
 
 	var (
 		stdin          io.WriteCloser // We write to stdin.
@@ -86,7 +87,7 @@
 
 		defer f.Close()
 
-		setWindowSize(ptyFd, shellOpts.WinSize.Rows, shellOpts.WinSize.Cols)
+		setWindowSize(ctx, ptyFd, shellOpts.WinSize.Rows, shellOpts.WinSize.Cols)
 	} else {
 		var err error
 		if stdin, err = c.StdinPipe(); err != nil {
@@ -105,7 +106,7 @@
 		defer stderr.Close()
 
 		if err = c.Start(); err != nil {
-			vlog.Infof("Cmd.Start failed: %v", err)
+			ctx.Infof("Cmd.Start failed: %v", err)
 			return nonShellErrorCode, err
 		}
 	}
@@ -115,7 +116,7 @@
 	select {
 	case runErr := <-runIOManager(stdin, stdout, stderr, ptyFd, call):
 		b, _ := security.RemoteBlessingNames(ctx, call.Security())
-		vlog.Infof("SHELL END for %v: %q (%v)", b, command, runErr)
+		ctx.Infof("SHELL END for %v: %q (%v)", b, command, runErr)
 		return harvestExitcode(c.Process, runErr)
 	case <-ctx.Done():
 		return nonShellErrorCode, fmt.Errorf("remote end exited")
@@ -155,7 +156,7 @@
 }
 
 // sendMotd sends the content of the MOTD file to the stream, if it exists.
-func sendMotd(s tunnel.TunnelShellServerStream) {
+func sendMotd(logger logging.Logger, s tunnel.TunnelShellServerStream) {
 	data, err := ioutil.ReadFile("/etc/motd")
 	if err != nil {
 		// No MOTD. That's OK.
@@ -163,13 +164,13 @@
 	}
 	packet := tunnel.ServerShellPacketStdout{[]byte(data)}
 	if err = s.SendStream().Send(packet); err != nil {
-		vlog.Infof("Send failed: %v", err)
+		logger.Infof("Send failed: %v", err)
 	}
 }
 
-func setWindowSize(fd uintptr, row, col uint16) {
+func setWindowSize(logger logging.Logger, fd uintptr, row, col uint16) {
 	ws := internal.Winsize{Row: row, Col: col}
 	if err := internal.SetWindowSize(fd, ws); err != nil {
-		vlog.Infof("Failed to set window size: %v", err)
+		logger.Infof("Failed to set window size: %v", err)
 	}
 }
diff --git a/examples/tunnel/tunneld/iomanager.go b/examples/tunnel/tunneld/iomanager.go
index 478bb62..509e2dc 100644
--- a/examples/tunnel/tunneld/iomanager.go
+++ b/examples/tunnel/tunneld/iomanager.go
@@ -9,8 +9,8 @@
 	"io"
 	"sync"
 
-	"v.io/x/lib/vlog"
 	"v.io/x/ref/examples/tunnel"
+	"v.io/x/ref/internal/logger"
 )
 
 func runIOManager(stdin io.WriteCloser, stdout, stderr io.Reader, ptyFd uintptr, stream tunnel.TunnelShellServerStream) <-chan error {
@@ -82,12 +82,12 @@
 	select {
 	case err := <-m.streamError:
 		// Process remaining input from the stream before exiting.
-		vlog.VI(2).Infof("run stream error: %v", err)
+		logger.Global().VI(2).Infof("run stream error: %v", err)
 		pendingStreamInput.Wait()
 		return err
 	case err := <-m.stdioError:
 		// Process remaining output from the shell before exiting.
-		vlog.VI(2).Infof("run stdio error: %v", err)
+		logger.Global().VI(2).Infof("run stdio error: %v", err)
 		pendingShellOutput.Wait()
 		return err
 	}
@@ -112,9 +112,9 @@
 	defer wg.Done()
 	sender := m.stream.SendStream()
 	for packet := range outchan {
-		vlog.VI(3).Infof("chan2stream packet: %+v", packet)
+		logger.Global().VI(3).Infof("chan2stream packet: %+v", packet)
 		if err := sender.Send(packet); err != nil {
-			vlog.VI(2).Infof("chan2stream: %v", err)
+			logger.Global().VI(2).Infof("chan2stream: %v", err)
 			m.sendStreamError(err)
 		}
 	}
@@ -127,7 +127,7 @@
 		buf := make([]byte, 2048)
 		n, err := m.stdout.Read(buf[:])
 		if err != nil {
-			vlog.VI(2).Infof("stdout2outchan: %v", err)
+			logger.Global().VI(2).Infof("stdout2outchan: %v", err)
 			m.sendStdioError(err)
 			return
 		}
@@ -142,7 +142,7 @@
 		buf := make([]byte, 2048)
 		n, err := m.stderr.Read(buf[:])
 		if err != nil {
-			vlog.VI(2).Infof("stderr2outchan: %v", err)
+			logger.Global().VI(2).Infof("stderr2outchan: %v", err)
 			m.sendStdioError(err)
 			return
 		}
@@ -156,7 +156,7 @@
 	rStream := m.stream.RecvStream()
 	for rStream.Advance() {
 		packet := rStream.Value()
-		vlog.VI(3).Infof("stream2stdin packet: %+v", packet)
+		logger.Global().VI(3).Infof("stream2stdin packet: %+v", packet)
 		switch v := packet.(type) {
 		case tunnel.ClientShellPacketStdin:
 			if n, err := m.stdin.Write(v.Value); n != len(v.Value) || err != nil {
@@ -171,10 +171,10 @@
 		case tunnel.ClientShellPacketWinSize:
 			size := v.Value
 			if size.Rows > 0 && size.Cols > 0 && m.ptyFd != 0 {
-				setWindowSize(m.ptyFd, size.Rows, size.Cols)
+				setWindowSize(logger.Global(), m.ptyFd, size.Rows, size.Cols)
 			}
 		default:
-			vlog.Infof("unexpected message type: %T", packet)
+			logger.Global().Infof("unexpected message type: %T", packet)
 		}
 	}
 
@@ -183,7 +183,7 @@
 		err = io.EOF
 	}
 
-	vlog.VI(2).Infof("stream2stdin: %v", err)
+	logger.Global().VI(2).Infof("stream2stdin: %v", err)
 	m.sendStreamError(err)
 	if err := m.stdin.Close(); err != nil {
 		m.sendStdioError(fmt.Errorf("stdin.Close: %v", err))
diff --git a/examples/tunnel/tunneld/main.go b/examples/tunnel/tunneld/main.go
index 05a44c2..b454ed2 100644
--- a/examples/tunnel/tunneld/main.go
+++ b/examples/tunnel/tunneld/main.go
@@ -10,10 +10,11 @@
 import (
 	"fmt"
 
+	"v.io/x/lib/cmdline"
+
 	"v.io/v23"
 	"v.io/v23/context"
-	"v.io/x/lib/cmdline"
-	"v.io/x/lib/vlog"
+
 	"v.io/x/ref/examples/tunnel"
 	"v.io/x/ref/lib/security/securityflag"
 	"v.io/x/ref/lib/signals"
@@ -55,11 +56,11 @@
 		return fmt.Errorf("Serve(%v) failed: %v", name, err)
 	}
 	status := server.Status()
-	vlog.Infof("Listening on: %v", status.Endpoints)
+	ctx.Infof("Listening on: %v", status.Endpoints)
 	if len(status.Endpoints) > 0 {
 		fmt.Printf("NAME=%s\n", status.Endpoints[0].Name())
 	}
-	vlog.Infof("Published as %q", name)
+	ctx.Infof("Published as %q", name)
 
 	<-signals.ShutdownOnSignals(ctx)
 	return nil
diff --git a/examples/tunnel/vsh/iomanager.go b/examples/tunnel/vsh/iomanager.go
index de41910..d0f6d95 100644
--- a/examples/tunnel/vsh/iomanager.go
+++ b/examples/tunnel/vsh/iomanager.go
@@ -12,9 +12,9 @@
 	"sync"
 	"syscall"
 
-	"v.io/x/lib/vlog"
 	"v.io/x/ref/examples/tunnel"
 	"v.io/x/ref/examples/tunnel/internal"
+	"v.io/x/ref/internal/logger"
 )
 
 func runIOManager(stdin io.Reader, stdout, stderr io.Writer, stream tunnel.TunnelShellClientCall) error {
@@ -81,14 +81,14 @@
 		// When we receive an error from the stream, wait for any
 		// remaining stream output to be sent to the user before
 		// exiting.
-		vlog.VI(2).Infof("run stream error: %v", err)
+		logger.Global().VI(2).Infof("run stream error: %v", err)
 		pendingStreamOutput.Wait()
 		return err
 	case err := <-m.stdioError:
 		// When we receive an error from the user, wait for any
 		// remaining input from the user to be sent to the stream
 		// before exiting.
-		vlog.VI(2).Infof("run stdio error: %v", err)
+		logger.Global().VI(2).Infof("run stdio error: %v", err)
 		pendingUserInput.Wait()
 		return err
 	}
@@ -113,9 +113,9 @@
 	defer wg.Done()
 	sender := m.stream.SendStream()
 	for packet := range outchan {
-		vlog.VI(3).Infof("chan2stream packet: %+v", packet)
+		logger.Global().VI(3).Infof("chan2stream packet: %+v", packet)
 		if err := sender.Send(packet); err != nil {
-			vlog.VI(2).Infof("chan2stream: %v", err)
+			logger.Global().VI(2).Infof("chan2stream: %v", err)
 			m.sendStreamError(err)
 		}
 	}
@@ -127,7 +127,7 @@
 	for _ = range winch {
 		ws, err := internal.GetWindowSize()
 		if err != nil {
-			vlog.Infof("GetWindowSize failed: %v", err)
+			logger.Global().Infof("GetWindowSize failed: %v", err)
 			continue
 		}
 		outchan <- tunnel.ClientShellPacketWinSize{tunnel.WindowSize{ws.Row, ws.Col}}
@@ -141,12 +141,12 @@
 		buf := make([]byte, 2048)
 		n, err := m.stdin.Read(buf[:])
 		if err == io.EOF {
-			vlog.VI(2).Infof("user2outchan: EOF, closing stdin")
+			logger.Global().VI(2).Infof("user2outchan: EOF, closing stdin")
 			outchan <- tunnel.ClientShellPacketEndOfFile{}
 			return
 		}
 		if err != nil {
-			vlog.VI(2).Infof("user2outchan: %v", err)
+			logger.Global().VI(2).Infof("user2outchan: %v", err)
 			m.sendStdioError(err)
 			return
 		}
@@ -160,7 +160,7 @@
 	rStream := m.stream.RecvStream()
 	for rStream.Advance() {
 		packet := rStream.Value()
-		vlog.VI(3).Infof("stream2user packet: %+v", packet)
+		logger.Global().VI(3).Infof("stream2user packet: %+v", packet)
 
 		switch v := packet.(type) {
 		case tunnel.ServerShellPacketStdout:
@@ -174,13 +174,13 @@
 				return
 			}
 		default:
-			vlog.Infof("unexpected message type: %T", packet)
+			logger.Global().Infof("unexpected message type: %T", packet)
 		}
 	}
 	err := rStream.Err()
 	if err == nil {
 		err = io.EOF
 	}
-	vlog.VI(2).Infof("stream2user: %v", err)
+	logger.Global().VI(2).Infof("stream2user: %v", err)
 	m.sendStreamError(err)
 }
diff --git a/examples/tunnel/vsh/main.go b/examples/tunnel/vsh/main.go
index d3a0ee7..55a0c44 100644
--- a/examples/tunnel/vsh/main.go
+++ b/examples/tunnel/vsh/main.go
@@ -13,14 +13,15 @@
 	"net"
 	"strings"
 
-	"v.io/v23/context"
 	"v.io/x/lib/cmdline"
-	"v.io/x/lib/vlog"
+
+	"v.io/v23/context"
+
 	"v.io/x/ref/examples/tunnel"
 	"v.io/x/ref/examples/tunnel/internal"
+	"v.io/x/ref/internal/logger"
 	"v.io/x/ref/lib/signals"
 	"v.io/x/ref/lib/v23cmd"
-
 	_ "v.io/x/ref/runtime/factories/generic"
 )
 
@@ -110,7 +111,7 @@
 	if err != nil {
 		exitMsg += fmt.Sprintf(" (%v)", err)
 	}
-	vlog.VI(1).Info(exitMsg)
+	ctx.VI(1).Info(exitMsg)
 	// Only show the exit message on stdout for interactive shells.
 	// Otherwise, the exit message might get confused with the output
 	// of the command that was run.
@@ -127,7 +128,7 @@
 	opts.Environment = environment(env.Vars)
 	ws, err := internal.GetWindowSize()
 	if err != nil {
-		vlog.VI(1).Infof("GetWindowSize failed: %v", err)
+		logger.Global().VI(1).Infof("GetWindowSize failed: %v", err)
 	} else {
 		opts.WinSize.Rows = ws.Row
 		opts.WinSize.Cols = ws.Col
@@ -173,35 +174,35 @@
 	parts := strings.Split(portforward, ",")
 	var laddr, raddr string
 	if len(parts) != 2 {
-		vlog.Fatalf("-L flag expects 2 values separated by a comma")
+		ctx.Fatalf("-L flag expects 2 values separated by a comma")
 	}
 	laddr = parts[0]
 	raddr = parts[1]
 
 	ln, err := net.Listen(lprotocol, laddr)
 	if err != nil {
-		vlog.Fatalf("net.Listen(%q, %q) failed: %v", lprotocol, laddr, err)
+		ctx.Fatalf("net.Listen(%q, %q) failed: %v", lprotocol, laddr, err)
 	}
 	defer ln.Close()
-	vlog.VI(1).Infof("Listening on %q", ln.Addr())
+	ctx.VI(1).Infof("Listening on %q", ln.Addr())
 	for {
 		conn, err := ln.Accept()
 		if err != nil {
-			vlog.Infof("Accept failed: %v", err)
+			ctx.Infof("Accept failed: %v", err)
 			continue
 		}
 		stream, err := t.Forward(ctx, rprotocol, raddr)
 		if err != nil {
-			vlog.Infof("Tunnel(%q, %q) failed: %v", rprotocol, raddr, err)
+			ctx.Infof("Tunnel(%q, %q) failed: %v", rprotocol, raddr, err)
 			conn.Close()
 			continue
 		}
 		name := fmt.Sprintf("%v-->%v-->(%v)-->%v", conn.RemoteAddr(), conn.LocalAddr(), oname, raddr)
 		go func() {
-			vlog.VI(1).Infof("TUNNEL START: %v", name)
+			ctx.VI(1).Infof("TUNNEL START: %v", name)
 			errf := internal.Forward(conn, stream.SendStream(), stream.RecvStream())
 			err := stream.Finish()
-			vlog.VI(1).Infof("TUNNEL END  : %v (%v, %v)", name, errf, err)
+			ctx.VI(1).Infof("TUNNEL END  : %v (%v, %v)", name, errf, err)
 		}()
 	}
 }