x/ref/services: profile, mounttable, proxy, role to use context-based logging.

MultiPart: 1/3

Change-Id: Ia8be0a142ba3a00f10ac156d1d5d0a687d9005c2
diff --git a/cmd/servicerunner/main.go b/cmd/servicerunner/main.go
index 34b7fe4..76e12e8 100644
--- a/cmd/servicerunner/main.go
+++ b/cmd/servicerunner/main.go
@@ -69,7 +69,7 @@
 	ctx, shutdown := v23.Init()
 	defer shutdown()
 
-	mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+	mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
 	if err != nil {
 		return fmt.Errorf("mounttablelib.NewMountTableDispatcher failed: %s", err)
 	}
diff --git a/examples/rps/rpsbot/impl_test.go b/examples/rps/rpsbot/impl_test.go
index ec2d3da..2e93780 100644
--- a/examples/rps/rpsbot/impl_test.go
+++ b/examples/rps/rpsbot/impl_test.go
@@ -33,7 +33,7 @@
 	ctx, shutdown := test.V23Init()
 	defer shutdown()
 
-	mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+	mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
 	if err != nil {
 		return fmt.Errorf("mounttablelib.NewMountTableDispatcher failed: %s", err)
 	}
diff --git a/runtime/internal/naming/namespace/all_test.go b/runtime/internal/naming/namespace/all_test.go
index 58be9fa..a27c68e 100644
--- a/runtime/internal/naming/namespace/all_test.go
+++ b/runtime/internal/naming/namespace/all_test.go
@@ -212,7 +212,7 @@
 }
 
 func runMT(t *testing.T, ctx *context.T, mountPoint string) *serverEntry {
-	mtd, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+	mtd, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
 	if err != nil {
 		boom(t, "NewMountTableDispatcher returned error: %v", err)
 	}
diff --git a/runtime/internal/rpc/resolve_test.go b/runtime/internal/rpc/resolve_test.go
index 2c33e04..da3649f 100644
--- a/runtime/internal/rpc/resolve_test.go
+++ b/runtime/internal/rpc/resolve_test.go
@@ -72,7 +72,7 @@
 	defer shutdown()
 
 	mp := ""
-	mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+	mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
 	if err != nil {
 		return fmt.Errorf("mounttablelib.NewMountTableDispatcher failed: %s", err)
 	}
diff --git a/runtime/internal/rpc/test/client_test.go b/runtime/internal/rpc/test/client_test.go
index e131796..c886455 100644
--- a/runtime/internal/rpc/test/client_test.go
+++ b/runtime/internal/rpc/test/client_test.go
@@ -52,7 +52,7 @@
 	ctx, shutdown := v23.Init()
 	defer shutdown()
 
-	mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+	mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
 	if err != nil {
 		return fmt.Errorf("mounttablelib.NewMountTableDispatcher failed: %s", err)
 	}
diff --git a/runtime/internal/vtrace/vtrace_test.go b/runtime/internal/vtrace/vtrace_test.go
index dbdb299..2a12083 100644
--- a/runtime/internal/vtrace/vtrace_test.go
+++ b/runtime/internal/vtrace/vtrace_test.go
@@ -43,7 +43,7 @@
 		t.Fatalf("Could not bless initial principal %v", err)
 	}
 	// Start a local mounttable.
-	disp, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+	disp, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
 	if err != nil {
 		t.Fatalf("Could not create mt dispatcher %v", err)
 	}
diff --git a/services/internal/servicetest/modules.go b/services/internal/servicetest/modules.go
index dcd226b..339af7c 100644
--- a/services/internal/servicetest/modules.go
+++ b/services/internal/servicetest/modules.go
@@ -36,7 +36,7 @@
 	ctx, shutdown := v23.Init()
 	defer shutdown()
 
-	mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+	mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
 	if err != nil {
 		return fmt.Errorf("mounttablelib.NewMountTableDispatcher failed: %s", err)
 	}
diff --git a/services/mounttable/mounttabled/mounttable.go b/services/mounttable/mounttabled/mounttable.go
index 2bc4363..72b8cef 100644
--- a/services/mounttable/mounttabled/mounttable.go
+++ b/services/mounttable/mounttabled/mounttable.go
@@ -13,7 +13,6 @@
 	"v.io/v23"
 	"v.io/v23/context"
 	"v.io/x/lib/cmdline"
-	"v.io/x/lib/vlog"
 	"v.io/x/ref/lib/signals"
 	"v.io/x/ref/lib/v23cmd"
 	_ "v.io/x/ref/runtime/factories/roaming"
@@ -54,6 +53,6 @@
 	fmt.Printf("NAME=%s\n", name)
 
 	// Wait until signal is received.
-	vlog.Info("Received signal ", <-signals.ShutdownOnSignals(ctx))
+	ctx.Info("Received signal ", <-signals.ShutdownOnSignals(ctx))
 	return nil
 }
diff --git a/services/mounttable/mounttablelib/mounttable.go b/services/mounttable/mounttablelib/mounttable.go
index 2885228..358c57f 100644
--- a/services/mounttable/mounttablelib/mounttable.go
+++ b/services/mounttable/mounttablelib/mounttable.go
@@ -21,8 +21,6 @@
 	"v.io/v23/services/mounttable"
 	"v.io/v23/verror"
 
-	"v.io/x/lib/vlog"
-
 	"v.io/x/ref/lib/glob"
 	"v.io/x/ref/lib/stats"
 )
@@ -62,6 +60,7 @@
 // mountTable represents a namespace.  One exists per server instance.
 type mountTable struct {
 	sync.Mutex
+	ctx                *context.T
 	root               *node
 	superUsers         access.AccessList
 	persisting         bool
@@ -114,8 +113,9 @@
 // persistDir is the directory for persisting Permissions.
 //
 // statsPrefix is the prefix for for exported statistics objects.
-func NewMountTableDispatcher(permsFile, persistDir, statsPrefix string) (rpc.Dispatcher, error) {
+func NewMountTableDispatcher(ctx *context.T, permsFile, persistDir, statsPrefix string) (rpc.Dispatcher, error) {
 	mt := &mountTable{
+		ctx:                ctx,
 		root:               new(node),
 		nodeCounter:        stats.NewInteger(naming.Join(statsPrefix, "num-nodes")),
 		serverCounter:      stats.NewInteger(naming.Join(statsPrefix, "num-mounted-servers")),
@@ -124,10 +124,10 @@
 	}
 	mt.root.parent = mt.newNode() // just for its lock
 	if persistDir != "" {
-		mt.persist = newPersistentStore(mt, persistDir)
+		mt.persist = newPersistentStore(ctx, mt, persistDir)
 		mt.persisting = mt.persist != nil
 	}
-	if err := mt.parsePermFile(permsFile); err != nil && !os.IsNotExist(err) {
+	if err := mt.parsePermFile(ctx, permsFile); err != nil && !os.IsNotExist(err) {
 		return nil, err
 	}
 	return mt, nil
@@ -178,7 +178,7 @@
 
 // Lookup implements rpc.Dispatcher.Lookup.
 func (mt *mountTable) Lookup(name string) (interface{}, security.Authorizer, error) {
-	vlog.VI(2).Infof("*********************Lookup %s", name)
+	mt.ctx.VI(2).Infof("*********************Lookup %s", name)
 	ms := &mountContext{
 		name: name,
 		mt:   mt,
@@ -292,7 +292,7 @@
 	cur.parent.Lock()
 	cur.Lock()
 	for i, e := range elems {
-		vlog.VI(2).Infof("satisfying %v %v", elems[0:i], *cur)
+		ctx.VI(2).Infof("satisfying %v %v", elems[0:i], *cur)
 		if call != nil {
 			if err := cur.satisfies(mt, ctx, call, traverseTags); err != nil {
 				cur.parent.Unlock()
@@ -413,7 +413,7 @@
 		// If we removed the node, see if we can remove any of its
 		// ascendants.
 		if removed && len(elems) > 0 {
-			mt.removeUselessRecursive(elems[:len(elems)-1])
+			mt.removeUselessRecursive(ctx, elems[:len(elems)-1])
 		}
 		return nil, nil, nil
 	}
@@ -429,7 +429,7 @@
 // ResolveStep returns the next server in a resolution in the form of a MountEntry.  The name
 // in the mount entry is the name relative to the server's root.
 func (ms *mountContext) ResolveStep(ctx *context.T, call rpc.ServerCall) (entry naming.MountEntry, err error) {
-	vlog.VI(2).Infof("ResolveStep %q", ms.name)
+	ctx.VI(2).Infof("ResolveStep %q", ms.name)
 	mt := ms.mt
 	// Find the next mount point for the name.
 	n, elems, werr := mt.findMountPoint(ctx, call.Security(), ms.elems)
@@ -480,7 +480,7 @@
 	if ttlsecs == 0 {
 		ttlsecs = 10 * 365 * 24 * 60 * 60 // a really long time
 	}
-	vlog.VI(2).Infof("*********************Mount %q -> %s", ms.name, server)
+	ctx.VI(2).Infof("*********************Mount %q -> %s", ms.name, server)
 
 	// Make sure the server address is reasonable.
 	epString := server
@@ -561,9 +561,9 @@
 }
 
 // removeUselessRecursive removes any useless nodes on the tail of the path.
-func (mt *mountTable) removeUselessRecursive(elems []string) {
+func (mt *mountTable) removeUselessRecursive(ctx *context.T, elems []string) {
 	for i := len(elems); i > 0; i-- {
-		n, nelems, _ := mt.traverse(nil, nil, elems[:i], false)
+		n, nelems, _ := mt.traverse(ctx, nil, elems[:i], false)
 		if n == nil {
 			break
 		}
@@ -584,7 +584,7 @@
 // Unmount removes servers from the name in the receiver. If server is specified, only that
 // server is removed.
 func (ms *mountContext) Unmount(ctx *context.T, call rpc.ServerCall, server string) error {
-	vlog.VI(2).Infof("*********************Unmount %q, %s", ms.name, server)
+	ctx.VI(2).Infof("*********************Unmount %q, %s", ms.name, server)
 	mt := ms.mt
 	n, err := mt.findNode(ctx, call.Security(), ms.elems, false, mountTags, nil)
 	if err != nil {
@@ -606,14 +606,14 @@
 	if removed {
 		// If we removed the node, see if we can also remove
 		// any of its ascendants.
-		mt.removeUselessRecursive(ms.elems[:len(ms.elems)-1])
+		mt.removeUselessRecursive(ctx, ms.elems[:len(ms.elems)-1])
 	}
 	return nil
 }
 
 // Delete removes the receiver.  If all is true, any subtree is also removed.
 func (ms *mountContext) Delete(ctx *context.T, call rpc.ServerCall, deleteSubTree bool) error {
-	vlog.VI(2).Infof("*********************Delete %q, %v", ms.name, deleteSubTree)
+	ctx.VI(2).Infof("*********************Delete %q, %v", ms.name, deleteSubTree)
 	if len(ms.elems) == 0 {
 		// We can't delete the root.
 		return verror.New(errCantDeleteRoot, ctx)
@@ -648,7 +648,7 @@
 
 // globStep is called with n and n.parent locked.  Returns with both unlocked.
 func (mt *mountTable) globStep(ctx *context.T, call security.Call, n *node, name string, pattern *glob.Glob, ch chan<- naming.GlobReply) {
-	vlog.VI(2).Infof("globStep(%s, %s)", name, pattern)
+	ctx.VI(2).Infof("globStep(%s, %s)", name, pattern)
 
 	// If this is a mount point, we're done.
 	if m := n.mount; m != nil {
@@ -753,7 +753,7 @@
 // adds a/b while a Glob is in progress, the Glob may return a set of nodes that includes both
 // c/d and a/b.
 func (ms *mountContext) Glob__(ctx *context.T, call rpc.ServerCall, pattern string) (<-chan naming.GlobReply, error) {
-	vlog.VI(2).Infof("mt.Glob %v", ms.elems)
+	ctx.VI(2).Infof("mt.Glob %v", ms.elems)
 	scall := call.Security()
 
 	g, err := glob.Parse(pattern)
@@ -797,7 +797,7 @@
 }
 
 func (ms *mountContext) SetPermissions(ctx *context.T, call rpc.ServerCall, perms access.Permissions, version string) error {
-	vlog.VI(2).Infof("SetPermissions %q", ms.name)
+	ctx.VI(2).Infof("SetPermissions %q", ms.name)
 	mt := ms.mt
 
 	// Find/create node in namespace and add the mount.
@@ -843,7 +843,7 @@
 }
 
 func (ms *mountContext) GetPermissions(ctx *context.T, call rpc.ServerCall) (access.Permissions, string, error) {
-	vlog.VI(2).Infof("GetPermissions %q", ms.name)
+	ctx.VI(2).Infof("GetPermissions %q", ms.name)
 	mt := ms.mt
 
 	// Find node in namespace and add the mount.
diff --git a/services/mounttable/mounttablelib/mounttable_test.go b/services/mounttable/mounttablelib/mounttable_test.go
index 4e08341..9d9df27 100644
--- a/services/mounttable/mounttablelib/mounttable_test.go
+++ b/services/mounttable/mounttablelib/mounttable_test.go
@@ -25,8 +25,8 @@
 	"v.io/v23/security/access"
 	"v.io/v23/services/stats"
 	"v.io/v23/vdl"
-	"v.io/x/lib/vlog"
 
+	"v.io/x/ref/internal/logger"
 	libstats "v.io/x/ref/lib/stats"
 	"v.io/x/ref/lib/xrpc"
 	"v.io/x/ref/services/debug/debuglib"
@@ -187,11 +187,11 @@
 }
 
 func newMT(t *testing.T, permsFile, persistDir, statsDir string, rootCtx *context.T) (func() error, string) {
-	reservedDisp := debuglib.NewDispatcher(vlog.Log.LogDir, nil)
+	reservedDisp := debuglib.NewDispatcher(logger.Manager(logger.Global()).LogDir, nil)
 	ctx := v23.WithReservedNameDispatcher(rootCtx, reservedDisp)
 
 	// Add mount table service.
-	mt, err := mounttablelib.NewMountTableDispatcher(permsFile, persistDir, statsDir)
+	mt, err := mounttablelib.NewMountTableDispatcher(ctx, permsFile, persistDir, statsDir)
 	if err != nil {
 		boom(t, "mounttablelib.NewMountTableDispatcher: %v", err)
 	}
@@ -231,15 +231,15 @@
 	collectionName := naming.JoinAddressName(collectionAddr, "collection")
 
 	// Mount the collection server into the mount table.
-	vlog.Infof("Mount the collection server into the mount table.")
+	rootCtx.Infof("Mount the collection server into the mount table.")
 	doMount(t, rootCtx, mtAddr, "stuff", collectionName, true)
 
 	// Create a few objects and make sure we can read them.
-	vlog.Infof("Create a few objects.")
+	rootCtx.Infof("Create a few objects.")
 	export(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/the/rain"), "the rain")
 	export(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/in/spain"), "in spain")
 	export(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/falls"), "falls mainly on the plain")
-	vlog.Infof("Make sure we can read them.")
+	rootCtx.Infof("Make sure we can read them.")
 	checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/the/rain"), "the rain", true)
 	checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/in/spain"), "in spain", true)
 	checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/falls"), "falls mainly on the plain", true)
@@ -249,11 +249,11 @@
 	checkContents(t, aliceCtx, naming.JoinAddressName(mtAddr, "stuff/the/rain"), "the rain", false)
 
 	// Test multiple mounts.
-	vlog.Infof("Multiple mounts.")
+	rootCtx.Infof("Multiple mounts.")
 	doMount(t, rootCtx, mtAddr, "a/b", collectionName, true)
 	doMount(t, rootCtx, mtAddr, "x/y", collectionName, true)
 	doMount(t, rootCtx, mtAddr, "alpha//beta", collectionName, true)
-	vlog.Infof("Make sure we can read them.")
+	rootCtx.Infof("Make sure we can read them.")
 	checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/falls"), "falls mainly on the plain", true)
 	checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "a/b/falls"), "falls mainly on the plain", true)
 	checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "x/y/falls"), "falls mainly on the plain", true)
@@ -296,18 +296,18 @@
 	}
 
 	// Test generic unmount.
-	vlog.Info("Test generic unmount.")
+	rootCtx.Info("Test generic unmount.")
 	doUnmount(t, rootCtx, mtAddr, "a/b", "", true)
 	checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "a/b/falls"), "falls mainly on the plain", false)
 
 	// Test specific unmount.
-	vlog.Info("Test specific unmount.")
+	rootCtx.Info("Test specific unmount.")
 	doMount(t, rootCtx, mtAddr, "a/b", collectionName, true)
 	doUnmount(t, rootCtx, mtAddr, "a/b", collectionName, true)
 	checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "a/b/falls"), "falls mainly on the plain", false)
 
 	// Try timing out a mount.
-	vlog.Info("Try timing out a mount.")
+	rootCtx.Info("Try timing out a mount.")
 	ft := mounttablelib.NewFakeTimeClock()
 	mounttablelib.SetServerListClock(ft)
 	doMount(t, rootCtx, mtAddr, "stuffWithTTL", collectionName, true)
@@ -316,7 +316,7 @@
 	checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "stuffWithTTL/the/rain"), "the rain", false)
 
 	// Test unauthorized mount.
-	vlog.Info("Test unauthorized mount.")
+	rootCtx.Info("Test unauthorized mount.")
 	doMount(t, bobCtx, mtAddr, "/a/b", collectionName, false)
 	doMount(t, aliceCtx, mtAddr, "/a/b", collectionName, false)
 
@@ -648,11 +648,13 @@
 }
 
 func TestBadAccessLists(t *testing.T) {
-	_, err := mounttablelib.NewMountTableDispatcher("testdata/invalid.perms", "", "mounttable")
+	ctx, shutdown := test.V23InitWithParams(test.InitParams{})
+	defer shutdown()
+	_, err := mounttablelib.NewMountTableDispatcher(ctx, "testdata/invalid.perms", "", "mounttable")
 	if err == nil {
 		boom(t, "Expected json parse error in permissions file")
 	}
-	_, err = mounttablelib.NewMountTableDispatcher("testdata/doesntexist.perms", "", "mounttable")
+	_, err = mounttablelib.NewMountTableDispatcher(ctx, "testdata/doesntexist.perms", "", "mounttable")
 	if err != nil {
 		boom(t, "Missing permissions file should not cause an error")
 	}
diff --git a/services/mounttable/mounttablelib/neighborhood.go b/services/mounttable/mounttablelib/neighborhood.go
index ac82af2..ef5b672 100644
--- a/services/mounttable/mounttablelib/neighborhood.go
+++ b/services/mounttable/mounttablelib/neighborhood.go
@@ -22,7 +22,8 @@
 	"v.io/v23/services/mounttable"
 	vdltime "v.io/v23/vdlroot/time"
 	"v.io/v23/verror"
-	"v.io/x/lib/vlog"
+
+	"v.io/x/ref/internal/logger"
 
 	mdns "github.com/presotto/go-mdns-sd"
 )
@@ -110,10 +111,10 @@
 	// Start up MDNS, subscribe to the vanadium service, and add us as a vanadium service provider.
 	mdns, err := mdns.NewMDNS(host, "", "", loopback, false)
 	if err != nil {
-		vlog.Errorf("mdns startup failed: %s", err)
+		logger.Global().Errorf("mdns startup failed: %s", err)
 		return nil, err
 	}
-	vlog.VI(2).Infof("listening for service vanadium on port %d", port)
+	logger.Global().VI(2).Infof("listening for service vanadium on port %d", port)
 	mdns.SubscribeToService("vanadium")
 	if host != AnonymousNeighbor {
 		mdns.AddService("vanadium", "", port, txt...)
@@ -128,7 +129,7 @@
 	// interfaces when the network changes.
 	nh.nw, err = netconfig.NewNetConfigWatcher()
 	if err != nil {
-		vlog.Errorf("nighborhood can't watch network: %s", err)
+		logger.Global().Errorf("nighborhood can't watch network: %s", err)
 		return nh, nil
 	}
 	go func() {
@@ -136,7 +137,7 @@
 			return
 		}
 		if _, err := nh.mdns.ScanInterfaces(); err != nil {
-			vlog.Errorf("nighborhood can't scan interfaces: %s", err)
+			logger.Global().Errorf("nighborhood can't scan interfaces: %s", err)
 		}
 	}()
 
@@ -157,7 +158,7 @@
 
 // Lookup implements rpc.Dispatcher.Lookup.
 func (nh *neighborhood) Lookup(name string) (interface{}, security.Authorizer, error) {
-	vlog.VI(1).Infof("*********************LookupServer '%s'\n", name)
+	logger.Global().VI(1).Infof("*********************LookupServer '%s'\n", name)
 	elems := strings.Split(name, "/")[nh.nelems:]
 	if name == "" {
 		elems = nil
@@ -225,14 +226,14 @@
 			neighbors[m.Name] = neighbor
 		}
 	}
-	vlog.VI(2).Infof("members %v neighbors %v", members, neighbors)
+	logger.Global().VI(2).Infof("members %v neighbors %v", members, neighbors)
 	return neighbors
 }
 
 // ResolveStep implements ResolveStep
 func (ns *neighborhoodService) ResolveStep(ctx *context.T, _ rpc.ServerCall) (entry naming.MountEntry, err error) {
 	nh := ns.nh
-	vlog.VI(2).Infof("ResolveStep %v\n", ns.elems)
+	ctx.VI(2).Infof("ResolveStep %v\n", ns.elems)
 	if len(ns.elems) == 0 {
 		//nothing can be mounted at the root
 		err = verror.New(naming.ErrNoSuchNameRoot, ctx, ns.elems)
diff --git a/services/mounttable/mounttablelib/neighborhood_test.go b/services/mounttable/mounttablelib/neighborhood_test.go
index bf0c918..b5c1ff1 100644
--- a/services/mounttable/mounttablelib/neighborhood_test.go
+++ b/services/mounttable/mounttablelib/neighborhood_test.go
@@ -14,7 +14,6 @@
 	"v.io/v23"
 	"v.io/v23/naming"
 	"v.io/v23/options"
-	"v.io/x/lib/vlog"
 
 	_ "v.io/x/ref/runtime/factories/generic"
 	"v.io/x/ref/services/mounttable/mounttablelib"
@@ -37,7 +36,7 @@
 	rootCtx, shutdown := test.V23Init()
 	defer shutdown()
 
-	vlog.Infof("TestNeighborhood")
+	rootCtx.Infof("TestNeighborhood")
 	server, err := v23.NewServer(rootCtx)
 	if err != nil {
 		boom(t, "r.NewServer: %s", err)
diff --git a/services/mounttable/mounttablelib/persistentstore.go b/services/mounttable/mounttablelib/persistentstore.go
index a96eb19..3132e59 100644
--- a/services/mounttable/mounttablelib/persistentstore.go
+++ b/services/mounttable/mounttablelib/persistentstore.go
@@ -12,7 +12,9 @@
 	"strings"
 	"sync"
 
-	"v.io/x/lib/vlog"
+	"v.io/v23/context"
+
+	"v.io/x/ref/internal/logger"
 )
 
 type store struct {
@@ -43,7 +45,7 @@
 //      it will be renamed persistent.perms becoming the new log.
 //   old.permslog - the previous version of persistent.perms.  This is left around primarily for debugging
 //      and as an emergency backup.
-func newPersistentStore(mt *mountTable, dir string) persistence {
+func newPersistentStore(ctx *context.T, mt *mountTable, dir string) persistence {
 	s := &store{mt: mt, dir: dir}
 	file := path.Join(dir, "persistent.permslog")
 	tmp := path.Join(dir, "tmp.permslog")
@@ -53,11 +55,11 @@
 	f, err := os.Open(file)
 	if err != nil {
 		if !os.IsNotExist(err) {
-			vlog.Fatalf("cannot open %s: %s", file, err)
+			logger.Global().Fatalf("cannot open %s: %s", file, err)
 		}
 		os.Rename(tmp, file)
 		if f, err = os.Open(file); err != nil && !os.IsNotExist(err) {
-			vlog.Fatalf("cannot open %s: %s", file, err)
+			logger.Global().Fatalf("cannot open %s: %s", file, err)
 		}
 	} else {
 		os.Remove(tmp)
@@ -65,10 +67,10 @@
 
 	// Parse the permissions file and apply it to the in memory tree.
 	if f != nil {
-		if err := s.parseLogFile(f); err != nil {
+		if err := s.parseLogFile(ctx, f); err != nil {
 			f.Close()
 			// Log the error but keep going.  There's not much else we can do.
-			vlog.Infof("parsing old persistent permissions file %s: %s", file, err)
+			logger.Global().Infof("parsing old persistent permissions file %s: %s", file, err)
 		}
 		f.Close()
 	}
@@ -78,9 +80,9 @@
 	f, err = os.OpenFile(tmp, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600)
 	if err != nil {
 		// Log the error but keep going, don't compress, just append to the current file.
-		vlog.Infof("can't rewrite persistent permissions file %s: %s", file, err)
+		logger.Global().Infof("can't rewrite persistent permissions file %s: %s", file, err)
 		if f, err = os.OpenFile(file, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600); err != nil {
-			vlog.Fatalf("can't append to log %s: %s", file, err)
+			logger.Global().Fatalf("can't append to log %s: %s", file, err)
 		}
 		f.Seek(0, 2)
 		s.enc = json.NewEncoder(f)
@@ -92,13 +94,13 @@
 
 	// Switch names and remove the old file.
 	if err := os.Remove(old); err != nil {
-		vlog.Infof("removing %s: %s", old, err)
+		ctx.Infof("removing %s: %s", old, err)
 	}
 	if err := os.Rename(file, old); err != nil {
-		vlog.Infof("renaming %s to %s: %s", file, old, err)
+		ctx.Infof("renaming %s to %s: %s", file, old, err)
 	}
 	if err := os.Rename(tmp, file); err != nil {
-		vlog.Fatalf("renaming %s to %s: %s", tmp, file, err)
+		ctx.Fatalf("renaming %s to %s: %s", tmp, file, err)
 	}
 
 	// Reopen the new log file.  We could have just kept around the encoder used
@@ -106,7 +108,7 @@
 	// points to the same file.  Only true on Unix like file systems.
 	f, err = os.OpenFile(file, os.O_WRONLY|os.O_APPEND, 0600)
 	if err != nil {
-		vlog.Fatalf("can't open %s: %s", file, err)
+		ctx.Fatalf("can't open %s: %s", file, err)
 	}
 	f.Seek(0, 2)
 	s.enc = json.NewEncoder(f)
@@ -114,11 +116,11 @@
 }
 
 // parseLogFile reads a file and parses the contained VersionedPermissions .
-func (s *store) parseLogFile(f *os.File) error {
+func (s *store) parseLogFile(ctx *context.T, f *os.File) error {
 	if f == nil {
 		return nil
 	}
-	vlog.VI(2).Infof("parseLogFile(%s)", f.Name())
+	ctx.VI(2).Infof("parseLogFile(%s)", f.Name())
 	mt := s.mt
 	decoder := json.NewDecoder(f)
 	for {
@@ -131,16 +133,16 @@
 		}
 
 		elems := strings.Split(e.N, "/")
-		n, err := mt.findNode(nil, nil, elems, true, nil, nil)
+		n, err := mt.findNode(ctx, nil, elems, true, nil, nil)
 		if n != nil || err == nil {
 			n.creator = e.C
 			if e.D {
 				mt.deleteNode(n.parent, elems[len(elems)-1])
-				vlog.VI(2).Infof("deleted %s", e.N)
+				ctx.VI(2).Infof("deleted %s", e.N)
 			} else {
 				n.vPerms = &e.V
 				n.explicitPermissions = true
-				vlog.VI(2).Infof("added versions permissions %v to %s", e.V, e.N)
+				ctx.VI(2).Infof("added versions permissions %v to %s", e.V, e.N)
 			}
 		}
 		n.parent.Unlock()
diff --git a/services/mounttable/mounttablelib/servers.go b/services/mounttable/mounttablelib/servers.go
index ef8c550..c9aebd4 100644
--- a/services/mounttable/mounttablelib/servers.go
+++ b/services/mounttable/mounttablelib/servers.go
@@ -12,6 +12,7 @@
 	"v.io/v23/naming"
 	"v.io/v23/options"
 	"v.io/v23/rpc"
+
 	"v.io/x/lib/vlog"
 	"v.io/x/ref/lib/xrpc"
 )
@@ -24,20 +25,21 @@
 		}
 	}
 
-	mt, err := NewMountTableDispatcher(permsFile, persistDir, debugPrefix)
+	mt, err := NewMountTableDispatcher(ctx, permsFile, persistDir, debugPrefix)
 	if err != nil {
 		vlog.Errorf("NewMountTable failed: %v", err)
 		return "", nil, err
 	}
 	mtServer, err := xrpc.NewDispatchingServer(ctx, mountName, mt, options.ServesMountTable(true))
 	if err != nil {
-		vlog.Errorf("v23.NewServer failed: %v", err)
+
+		ctx.Errorf("v23.NewServer failed: %v", err)
 		return "", nil, err
 	}
 	stopFuncs = append(stopFuncs, mtServer.Stop)
 	mtEndpoints := mtServer.Status().Endpoints
 	mtName := mtEndpoints[0].Name()
-	vlog.Infof("Mount table service at: %q endpoint: %s", mountName, mtName)
+	ctx.Infof("Mount table service at: %q endpoint: %s", mountName, mtName)
 
 	if len(nhName) > 0 {
 		// The ListenSpec code ensures that we have a valid address here.
@@ -61,7 +63,7 @@
 
 		nhServer, err := xrpc.NewDispatchingServer(ctx, naming.Join(mtName, "nh"), nh, options.ServesMountTable(true))
 		if err != nil {
-			vlog.Errorf("v23.NewServer failed: %v", err)
+			ctx.Errorf("v23.NewServer failed: %v", err)
 			stop()
 			return "", nil, err
 		}
diff --git a/services/mounttable/mounttablelib/versionedpermissions.go b/services/mounttable/mounttablelib/versionedpermissions.go
index d4da750..661f9bb 100644
--- a/services/mounttable/mounttablelib/versionedpermissions.go
+++ b/services/mounttable/mounttablelib/versionedpermissions.go
@@ -18,7 +18,6 @@
 	"v.io/v23/security/access"
 	"v.io/v23/services/mounttable"
 	"v.io/v23/verror"
-	"v.io/x/lib/vlog"
 )
 
 // Blessings can't include a comma so we use them in made up user ids.  The following distinctions are
@@ -89,8 +88,8 @@
 }
 
 // parsePermFile reads a file and parses the contained permissions.
-func (mt *mountTable) parsePermFile(path string) error {
-	vlog.VI(2).Infof("parsePermFile(%s)", path)
+func (mt *mountTable) parsePermFile(ctx *context.T, path string) error {
+	ctx.VI(2).Infof("parsePermFile(%s)", path)
 	if path == "" {
 		return nil
 	}
@@ -143,9 +142,9 @@
 			}
 
 			// Create name and add the Permissions map to it.
-			n, err := mt.findNode(nil, nil, elems, true, nil, nil)
+			n, err := mt.findNode(ctx, nil, elems, true, nil, nil)
 			if n != nil || err == nil {
-				vlog.VI(2).Infof("added perms %v to %s", perms, name)
+				ctx.VI(2).Infof("added perms %v to %s", perms, name)
 				if isPattern {
 					n.permsTemplate = perms
 				} else {
diff --git a/services/profile/profile/impl_test.go b/services/profile/profile/impl_test.go
index e3695fb..98debf6 100644
--- a/services/profile/profile/impl_test.go
+++ b/services/profile/profile/impl_test.go
@@ -17,7 +17,6 @@
 	"v.io/v23/services/build"
 
 	"v.io/x/lib/cmdline"
-	"v.io/x/lib/vlog"
 	"v.io/x/ref/lib/v23cmd"
 	"v.io/x/ref/lib/xrpc"
 	_ "v.io/x/ref/runtime/factories/generic"
@@ -44,37 +43,37 @@
 	suffix string
 }
 
-func (s *server) Label(*context.T, rpc.ServerCall) (string, error) {
-	vlog.VI(2).Infof("%v.Label() was called", s.suffix)
+func (s *server) Label(ctx *context.T, _ rpc.ServerCall) (string, error) {
+	ctx.VI(2).Infof("%v.Label() was called", s.suffix)
 	if s.suffix != "exists" {
 		return "", fmt.Errorf("profile doesn't exist: %v", s.suffix)
 	}
 	return spec.Label, nil
 }
 
-func (s *server) Description(*context.T, rpc.ServerCall) (string, error) {
-	vlog.VI(2).Infof("%v.Description() was called", s.suffix)
+func (s *server) Description(ctx *context.T, _ rpc.ServerCall) (string, error) {
+	ctx.VI(2).Infof("%v.Description() was called", s.suffix)
 	if s.suffix != "exists" {
 		return "", fmt.Errorf("profile doesn't exist: %v", s.suffix)
 	}
 	return spec.Description, nil
 }
 
-func (s *server) Specification(*context.T, rpc.ServerCall) (profile.Specification, error) {
-	vlog.VI(2).Infof("%v.Specification() was called", s.suffix)
+func (s *server) Specification(ctx *context.T, _ rpc.ServerCall) (profile.Specification, error) {
+	ctx.VI(2).Infof("%v.Specification() was called", s.suffix)
 	if s.suffix != "exists" {
 		return profile.Specification{}, fmt.Errorf("profile doesn't exist: %v", s.suffix)
 	}
 	return spec, nil
 }
 
-func (s *server) Put(_ *context.T, _ rpc.ServerCall, _ profile.Specification) error {
-	vlog.VI(2).Infof("%v.Put() was called", s.suffix)
+func (s *server) Put(ctx *context.T, _ rpc.ServerCall, _ profile.Specification) error {
+	ctx.VI(2).Infof("%v.Put() was called", s.suffix)
 	return nil
 }
 
-func (s *server) Remove(*context.T, rpc.ServerCall) error {
-	vlog.VI(2).Infof("%v.Remove() was called", s.suffix)
+func (s *server) Remove(ctx *context.T, _ rpc.ServerCall) error {
+	ctx.VI(2).Infof("%v.Remove() was called", s.suffix)
 	if s.suffix != "exists" {
 		return fmt.Errorf("profile doesn't exist: %v", s.suffix)
 	}
diff --git a/services/profile/profiled/main.go b/services/profile/profiled/main.go
index 72518f7..93cf635 100644
--- a/services/profile/profiled/main.go
+++ b/services/profile/profiled/main.go
@@ -12,7 +12,6 @@
 
 	"v.io/v23/context"
 	"v.io/x/lib/cmdline"
-	"v.io/x/lib/vlog"
 	"v.io/x/ref/lib/security/securityflag"
 	"v.io/x/ref/lib/signals"
 	"v.io/x/ref/lib/v23cmd"
@@ -54,7 +53,7 @@
 	if err != nil {
 		return fmt.Errorf("NewServer() failed: %v", err)
 	}
-	vlog.Infof("Profile repository running at endpoint=%v", server.Status().Endpoints[0])
+	ctx.Infof("Profile repository running at endpoint=%v", server.Status().Endpoints[0])
 
 	// Wait until shutdown.
 	<-signals.ShutdownOnSignals(ctx)
diff --git a/services/profile/profiled/service.go b/services/profile/profiled/service.go
index d30613f..9f8f689 100644
--- a/services/profile/profiled/service.go
+++ b/services/profile/profiled/service.go
@@ -14,7 +14,6 @@
 	"v.io/v23/context"
 	"v.io/v23/naming"
 	"v.io/v23/rpc"
-	"v.io/x/lib/vlog"
 )
 
 // profileService implements the Profile server interface.
@@ -40,7 +39,7 @@
 // STORE MANAGEMENT INTERFACE IMPLEMENTATION
 
 func (i *profileService) Put(ctx *context.T, call rpc.ServerCall, profile profile.Specification) error {
-	vlog.VI(0).Infof("%v.Put(%v)", i.suffix, profile)
+	ctx.VI(0).Infof("%v.Put(%v)", i.suffix, profile)
 	// Transaction is rooted at "", so tname == tid.
 	i.store.Lock()
 	defer i.store.Unlock()
@@ -60,7 +59,7 @@
 }
 
 func (i *profileService) Remove(ctx *context.T, call rpc.ServerCall) error {
-	vlog.VI(0).Infof("%v.Remove()", i.suffix)
+	ctx.VI(0).Infof("%v.Remove()", i.suffix)
 	i.store.Lock()
 	defer i.store.Unlock()
 	// Transaction is rooted at "", so tname == tid.
@@ -107,7 +106,7 @@
 }
 
 func (i *profileService) Label(ctx *context.T, call rpc.ServerCall) (string, error) {
-	vlog.VI(0).Infof("%v.Label()", i.suffix)
+	ctx.VI(0).Infof("%v.Label()", i.suffix)
 	s, err := i.lookup(call)
 	if err != nil {
 		return "", err
@@ -116,7 +115,7 @@
 }
 
 func (i *profileService) Description(ctx *context.T, call rpc.ServerCall) (string, error) {
-	vlog.VI(0).Infof("%v.Description()", i.suffix)
+	ctx.VI(0).Infof("%v.Description()", i.suffix)
 	s, err := i.lookup(call)
 	if err != nil {
 		return "", err
@@ -125,6 +124,6 @@
 }
 
 func (i *profileService) Specification(ctx *context.T, call rpc.ServerCall) (profile.Specification, error) {
-	vlog.VI(0).Infof("%v.Specification()", i.suffix)
+	ctx.VI(0).Infof("%v.Specification()", i.suffix)
 	return i.lookup(call)
 }
diff --git a/services/proxy/proxyd/main.go b/services/proxy/proxyd/main.go
index 42053e9..1333581 100644
--- a/services/proxy/proxyd/main.go
+++ b/services/proxy/proxyd/main.go
@@ -14,13 +14,15 @@
 	"net/http"
 	"time"
 
+	"v.io/x/lib/cmdline"
+
 	"v.io/v23"
 	"v.io/v23/context"
+	"v.io/v23/logging"
 	"v.io/v23/rpc"
 	"v.io/v23/security"
 	"v.io/v23/security/access"
-	"v.io/x/lib/cmdline"
-	"v.io/x/lib/vlog"
+
 	"v.io/x/ref/lib/signals"
 	"v.io/x/ref/lib/v23cmd"
 	"v.io/x/ref/lib/xrpc"
@@ -66,7 +68,7 @@
 		// Always add ourselves, for the the reserved methods server
 		// started below.
 		list.In = append(list.In, security.DefaultBlessingPatterns(v23.GetPrincipal(ctx))...)
-		vlog.Infof("Using access list to control proxy use: %v", list)
+		ctx.Infof("Using access list to control proxy use: %v", list)
 		authorizer = list
 	}
 
@@ -85,7 +87,7 @@
 	}
 
 	if len(healthzAddr) != 0 {
-		go startHealthzServer(healthzAddr)
+		go startHealthzServer(ctx, healthzAddr)
 	}
 
 	// Start an RPC Server that listens through the proxy itself. This
@@ -120,7 +122,7 @@
 // startHealthzServer starts a HTTP server that simply returns "ok" to every
 // request. This is needed to let the load balancer know that the proxy server
 // is running.
-func startHealthzServer(addr string) {
+func startHealthzServer(logger logging.Logger, addr string) {
 	s := http.Server{
 		Addr:         addr,
 		Handler:      healthzHandler{},
@@ -128,6 +130,6 @@
 		WriteTimeout: 10 * time.Second,
 	}
 	if err := s.ListenAndServe(); err != nil {
-		vlog.Fatal(err)
+		logger.Fatal(err)
 	}
 }
diff --git a/services/role/roled/internal/discharger.go b/services/role/roled/internal/discharger.go
index 2a624cc..d6db009 100644
--- a/services/role/roled/internal/discharger.go
+++ b/services/role/roled/internal/discharger.go
@@ -14,13 +14,11 @@
 	"v.io/v23/verror"
 
 	"v.io/x/ref/services/discharger"
-
-	"v.io/x/lib/vlog"
 )
 
 func init() {
-	security.RegisterCaveatValidator(LoggingCaveat, func(_ *context.T, _ security.Call, params []string) error {
-		vlog.Infof("Params: %#v", params)
+	security.RegisterCaveatValidator(LoggingCaveat, func(ctx *context.T, _ security.Call, params []string) error {
+		ctx.Infof("Params: %#v", params)
 		return nil
 	})
 
@@ -39,7 +37,7 @@
 		return security.Discharge{}, err
 	}
 	// TODO(rthellend,ashankar): Do proper logging when the API allows it.
-	vlog.Infof("Discharge() impetus: %#v", impetus)
+	ctx.Infof("Discharge() impetus: %#v", impetus)
 
 	expiry, err := security.NewExpiryCaveat(time.Now().Add(5 * time.Minute))
 	if err != nil {
diff --git a/services/role/roled/internal/dispatcher.go b/services/role/roled/internal/dispatcher.go
index 475beb5..f741d34 100644
--- a/services/role/roled/internal/dispatcher.go
+++ b/services/role/roled/internal/dispatcher.go
@@ -16,10 +16,9 @@
 	"v.io/v23/security"
 	"v.io/v23/verror"
 
+	"v.io/x/ref/internal/logger"
 	"v.io/x/ref/services/discharger"
 	"v.io/x/ref/services/role"
-
-	"v.io/x/lib/vlog"
 )
 
 const requiredSuffix = security.ChainSeparator + role.RoleSuffix
@@ -58,7 +57,7 @@
 	if err != nil && !os.IsNotExist(err) {
 		// The config file exists, but we failed to read it for some
 		// reason. This is likely a server configuration error.
-		vlog.Errorf("loadConfig(%q, %q): %v", d.config.root, suffix, err)
+		logger.Global().Errorf("loadConfig(%q, %q): %v", d.config.root, suffix, err)
 		return nil, nil, verror.Convert(verror.ErrInternal, nil, err)
 	}
 	obj := &roleService{serverConfig: d.config, role: suffix, roleConfig: roleConfig}
@@ -112,7 +111,6 @@
 		f := filepath.Join(parentDir, filepath.FromSlash(imp+".conf"))
 		ic, err := loadExpandedConfig(f, seenFiles)
 		if err != nil {
-			vlog.Errorf("loadExpandedConfig(%q) failed: %v", f, err)
 			continue
 		}
 		if ic == nil {
diff --git a/services/role/roled/internal/role.go b/services/role/roled/internal/role.go
index 9d0e332..a46a31d 100644
--- a/services/role/roled/internal/role.go
+++ b/services/role/roled/internal/role.go
@@ -14,8 +14,6 @@
 	"v.io/v23/security"
 	"v.io/v23/verror"
 
-	"v.io/x/lib/vlog"
-
 	"v.io/x/ref/services/role"
 )
 
@@ -31,7 +29,7 @@
 
 func (i *roleService) SeekBlessings(ctx *context.T, call rpc.ServerCall) (security.Blessings, error) {
 	remoteBlessingNames, _ := security.RemoteBlessingNames(ctx, call.Security())
-	vlog.Infof("%q.SeekBlessings() called by %q", i.role, remoteBlessingNames)
+	ctx.Infof("%q.SeekBlessings() called by %q", i.role, remoteBlessingNames)
 
 	members := i.filterNonMembers(remoteBlessingNames)
 	if len(members) == 0 {
diff --git a/services/wspr/internal/app/app_test.go b/services/wspr/internal/app/app_test.go
index b9d242f..69cc32e 100644
--- a/services/wspr/internal/app/app_test.go
+++ b/services/wspr/internal/app/app_test.go
@@ -315,7 +315,7 @@
 }
 
 func serveServer(ctx *context.T, writer lib.ClientWriter, setController func(*Controller)) (*runningTest, error) {
-	mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+	mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
 	if err != nil {
 		return nil, fmt.Errorf("unable to start mounttable: %v", err)
 	}
diff --git a/services/wspr/internal/browspr/browspr_test.go b/services/wspr/internal/browspr/browspr_test.go
index 270d263..5841efa 100644
--- a/services/wspr/internal/browspr/browspr_test.go
+++ b/services/wspr/internal/browspr/browspr_test.go
@@ -77,7 +77,7 @@
 	}
 	defer proxyShutdown()
 
-	mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+	mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
 	if err != nil {
 		t.Fatalf("Failed to create mounttable: %v", err)
 	}
diff --git a/test/init.go b/test/init.go
index fae8ba3..0dc5cf7 100644
--- a/test/init.go
+++ b/test/init.go
@@ -39,7 +39,7 @@
 }
 
 // Init sets up state for running tests: Adjusting GOMAXPROCS,
-// configuring the vlog logging library, setting up the random number generator
+// configuring the logging library, setting up the random number generator
 // etc.
 //
 // Doing so requires flags to be parsed, so this function explicitly parses
@@ -96,7 +96,7 @@
 		}
 	}
 	if params.CreateMounttable {
-		disp, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+		disp, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
 		if err != nil {
 			panic(err)
 		}