Procházet zdrojové kódy

Rename ContextLogger to TraceLogger

Rod Hynes před 6 roky
rodič
revize
e864421ae3

+ 6 - 6
psiphon/common/logger.go

@@ -20,19 +20,19 @@
 package common
 package common
 
 
 // Logger exposes a logging interface that's compatible with
 // Logger exposes a logging interface that's compatible with
-// psiphon/server.ContextLogger. This interface allows packages
+// psiphon/server.TraceLogger. This interface allows packages
 // to implement logging that will integrate with psiphon/server
 // to implement logging that will integrate with psiphon/server
 // without importing that package. Other implementations of
 // without importing that package. Other implementations of
 // Logger may also be provided.
 // Logger may also be provided.
 type Logger interface {
 type Logger interface {
-	WithContext() LogContext
-	WithContextFields(fields LogFields) LogContext
+	WithTrace() LogTrace
+	WithTraceFields(fields LogFields) LogTrace
 	LogMetric(metric string, fields LogFields)
 	LogMetric(metric string, fields LogFields)
 }
 }
 
 
-// LogContext is interface-compatible with the return values from
-// psiphon/server.ContextLogger.WithContext/WithContextFields.
-type LogContext interface {
+// LogTrace is interface-compatible with the return values from
+// psiphon/server.TraceLogger.WitTrace/WithTraceFields.
+type LogTrace interface {
 	Debug(args ...interface{})
 	Debug(args ...interface{})
 	Info(args ...interface{})
 	Info(args ...interface{})
 	Warning(args ...interface{})
 	Warning(args ...interface{})

+ 7 - 7
psiphon/common/profiles.go

@@ -50,7 +50,7 @@ func WriteRuntimeProfiles(
 		file, err := os.OpenFile(
 		file, err := os.OpenFile(
 			filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
 			filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
 		if err != nil {
 		if err != nil {
-			logger.WithContextFields(
+			logger.WithTraceFields(
 				LogFields{
 				LogFields{
 					"error":    err,
 					"error":    err,
 					"fileName": filename}).Error("open profile file failed")
 					"fileName": filename}).Error("open profile file failed")
@@ -68,7 +68,7 @@ func WriteRuntimeProfiles(
 		err := pprof.Lookup(profileName).WriteTo(file, 1)
 		err := pprof.Lookup(profileName).WriteTo(file, 1)
 		file.Close()
 		file.Close()
 		if err != nil {
 		if err != nil {
-			logger.WithContextFields(
+			logger.WithTraceFields(
 				LogFields{
 				LogFields{
 					"error":       err,
 					"error":       err,
 					"profileName": profileName}).Error("write profile failed")
 					"profileName": profileName}).Error("write profile failed")
@@ -91,15 +91,15 @@ func WriteRuntimeProfiles(
 	if cpuSampleDurationSeconds > 0 {
 	if cpuSampleDurationSeconds > 0 {
 		file := openProfileFile("cpu")
 		file := openProfileFile("cpu")
 		if file != nil {
 		if file != nil {
-			logger.WithContext().Info("start cpu profiling")
+			logger.WithTrace().Info("start cpu profiling")
 			err := pprof.StartCPUProfile(file)
 			err := pprof.StartCPUProfile(file)
 			if err != nil {
 			if err != nil {
-				logger.WithContextFields(
+				logger.WithTraceFields(
 					LogFields{"error": err}).Error("StartCPUProfile failed")
 					LogFields{"error": err}).Error("StartCPUProfile failed")
 			} else {
 			} else {
 				time.Sleep(time.Duration(cpuSampleDurationSeconds) * time.Second)
 				time.Sleep(time.Duration(cpuSampleDurationSeconds) * time.Second)
 				pprof.StopCPUProfile()
 				pprof.StopCPUProfile()
-				logger.WithContext().Info("end cpu profiling")
+				logger.WithTrace().Info("end cpu profiling")
 			}
 			}
 			file.Close()
 			file.Close()
 		}
 		}
@@ -109,13 +109,13 @@ func WriteRuntimeProfiles(
 	// https://golang.org/pkg/runtime/pprof/#Profile
 	// https://golang.org/pkg/runtime/pprof/#Profile
 
 
 	if blockSampleDurationSeconds > 0 {
 	if blockSampleDurationSeconds > 0 {
-		logger.WithContext().Info("start block/mutex profiling")
+		logger.WithTrace().Info("start block/mutex profiling")
 		runtime.SetBlockProfileRate(1)
 		runtime.SetBlockProfileRate(1)
 		runtime.SetMutexProfileFraction(1)
 		runtime.SetMutexProfileFraction(1)
 		time.Sleep(time.Duration(blockSampleDurationSeconds) * time.Second)
 		time.Sleep(time.Duration(blockSampleDurationSeconds) * time.Second)
 		runtime.SetBlockProfileRate(0)
 		runtime.SetBlockProfileRate(0)
 		runtime.SetMutexProfileFraction(0)
 		runtime.SetMutexProfileFraction(0)
-		logger.WithContext().Info("end block/mutex profiling")
+		logger.WithTrace().Info("end block/mutex profiling")
 		writeProfile("block")
 		writeProfile("block")
 		writeProfile("mutex")
 		writeProfile("mutex")
 	}
 	}

+ 1 - 1
psiphon/common/profiles_test.go

@@ -49,7 +49,7 @@ func (logger *testLogger) WithContext() LogContext {
 	return &testLoggerContext{}
 	return &testLoggerContext{}
 }
 }
 
 
-func (logger *testLogger) WithContextFields(fields LogFields) LogContext {
+func (logger *testLogger) WithTraceFields(fields LogFields) LogContext {
 	return &testLoggerContext{}
 	return &testLoggerContext{}
 }
 }
 
 

+ 2 - 2
psiphon/common/quic/quic.go

@@ -484,10 +484,10 @@ func (conn *loggingPacketConn) ReadFrom(p []byte) (int, net.Addr, error) {
 		if err != nil && conn.logger != nil {
 		if err != nil && conn.logger != nil {
 			message := "ReadFrom failed"
 			message := "ReadFrom failed"
 			if e, ok := err.(net.Error); ok && e.Temporary() {
 			if e, ok := err.(net.Error); ok && e.Temporary() {
-				conn.logger.WithContextFields(
+				conn.logger.WithTraceFields(
 					common.LogFields{"error": err}).Debug(message)
 					common.LogFields{"error": err}).Debug(message)
 			} else {
 			} else {
-				conn.logger.WithContextFields(
+				conn.logger.WithTraceFields(
 					common.LogFields{"error": err}).Warning(message)
 					common.LogFields{"error": err}).Warning(message)
 			}
 			}
 		}
 		}

+ 10 - 10
psiphon/common/tactics/tactics.go

@@ -968,7 +968,7 @@ func (server *Server) handleSpeedTestRequest(
 
 
 	_, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, MAX_REQUEST_BODY_SIZE))
 	_, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, MAX_REQUEST_BODY_SIZE))
 	if err != nil {
 	if err != nil {
-		server.logger.WithContextFields(
+		server.logger.WithTraceFields(
 			common.LogFields{"error": err}).Warning("failed to read request body")
 			common.LogFields{"error": err}).Warning("failed to read request body")
 		common.TerminateHTTPConnection(w, r)
 		common.TerminateHTTPConnection(w, r)
 		return
 		return
@@ -977,7 +977,7 @@ func (server *Server) handleSpeedTestRequest(
 	response, err := MakeSpeedTestResponse(
 	response, err := MakeSpeedTestResponse(
 		SPEED_TEST_PADDING_MIN_SIZE, SPEED_TEST_PADDING_MAX_SIZE)
 		SPEED_TEST_PADDING_MIN_SIZE, SPEED_TEST_PADDING_MAX_SIZE)
 	if err != nil {
 	if err != nil {
-		server.logger.WithContextFields(
+		server.logger.WithTraceFields(
 			common.LogFields{"error": err}).Warning("failed to make response")
 			common.LogFields{"error": err}).Warning("failed to make response")
 		common.TerminateHTTPConnection(w, r)
 		common.TerminateHTTPConnection(w, r)
 		return
 		return
@@ -999,7 +999,7 @@ func (server *Server) handleTacticsRequest(
 
 
 	boxedRequest, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, MAX_REQUEST_BODY_SIZE))
 	boxedRequest, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, MAX_REQUEST_BODY_SIZE))
 	if err != nil {
 	if err != nil {
-		server.logger.WithContextFields(
+		server.logger.WithTraceFields(
 			common.LogFields{"error": err}).Warning("failed to read request body")
 			common.LogFields{"error": err}).Warning("failed to read request body")
 		common.TerminateHTTPConnection(w, r)
 		common.TerminateHTTPConnection(w, r)
 		return
 		return
@@ -1014,7 +1014,7 @@ func (server *Server) handleTacticsRequest(
 		boxedRequest,
 		boxedRequest,
 		&apiParams)
 		&apiParams)
 	if err != nil {
 	if err != nil {
-		server.logger.WithContextFields(
+		server.logger.WithTraceFields(
 			common.LogFields{"error": err}).Warning("failed to unbox request")
 			common.LogFields{"error": err}).Warning("failed to unbox request")
 		common.TerminateHTTPConnection(w, r)
 		common.TerminateHTTPConnection(w, r)
 		return
 		return
@@ -1022,7 +1022,7 @@ func (server *Server) handleTacticsRequest(
 
 
 	err = server.apiParameterValidator(apiParams)
 	err = server.apiParameterValidator(apiParams)
 	if err != nil {
 	if err != nil {
-		server.logger.WithContextFields(
+		server.logger.WithTraceFields(
 			common.LogFields{"error": err}).Warning("invalid request parameters")
 			common.LogFields{"error": err}).Warning("invalid request parameters")
 		common.TerminateHTTPConnection(w, r)
 		common.TerminateHTTPConnection(w, r)
 		return
 		return
@@ -1033,7 +1033,7 @@ func (server *Server) handleTacticsRequest(
 		err = errors.TraceNew("unexpected missing tactics payload")
 		err = errors.TraceNew("unexpected missing tactics payload")
 	}
 	}
 	if err != nil {
 	if err != nil {
-		server.logger.WithContextFields(
+		server.logger.WithTraceFields(
 			common.LogFields{"error": err}).Warning("failed to get tactics")
 			common.LogFields{"error": err}).Warning("failed to get tactics")
 		common.TerminateHTTPConnection(w, r)
 		common.TerminateHTTPConnection(w, r)
 		return
 		return
@@ -1049,7 +1049,7 @@ func (server *Server) handleTacticsRequest(
 		nil,
 		nil,
 		tacticsPayload)
 		tacticsPayload)
 	if err != nil {
 	if err != nil {
-		server.logger.WithContextFields(
+		server.logger.WithTraceFields(
 			common.LogFields{"error": err}).Warning("failed to box response")
 			common.LogFields{"error": err}).Warning("failed to box response")
 		common.TerminateHTTPConnection(w, r)
 		common.TerminateHTTPConnection(w, r)
 		return
 		return
@@ -1115,7 +1115,7 @@ func (listener *Listener) Accept() (net.Conn, error) {
 
 
 		tactics, err := listener.server.getTactics(true, geoIPData, make(common.APIParameters))
 		tactics, err := listener.server.getTactics(true, geoIPData, make(common.APIParameters))
 		if err != nil {
 		if err != nil {
-			listener.server.logger.WithContextFields(
+			listener.server.logger.WithTraceFields(
 				common.LogFields{"error": err}).Warning("failed to get tactics for connection")
 				common.LogFields{"error": err}).Warning("failed to get tactics for connection")
 			// If tactics is somehow misconfigured, keep handling connections.
 			// If tactics is somehow misconfigured, keep handling connections.
 			// Other error cases that follow below take the same approach.
 			// Other error cases that follow below take the same approach.
@@ -1162,7 +1162,7 @@ func (listener *Listener) Accept() (net.Conn, error) {
 		if listener.tunnelProtocol != protocol.TUNNEL_PROTOCOL_OBFUSCATED_SSH {
 		if listener.tunnelProtocol != protocol.TUNNEL_PROTOCOL_OBFUSCATED_SSH {
 			seed, err = prng.NewSeed()
 			seed, err = prng.NewSeed()
 			if err != nil {
 			if err != nil {
-				listener.server.logger.WithContextFields(
+				listener.server.logger.WithTraceFields(
 					common.LogFields{"error": err}).Warning("failed to seed fragmentor PRNG")
 					common.LogFields{"error": err}).Warning("failed to seed fragmentor PRNG")
 				return conn, nil
 				return conn, nil
 			}
 			}
@@ -1175,7 +1175,7 @@ func (listener *Listener) Accept() (net.Conn, error) {
 			conn = fragmentor.NewConn(
 			conn = fragmentor.NewConn(
 				fragmentorConfig,
 				fragmentorConfig,
 				func(message string) {
 				func(message string) {
-					listener.server.logger.WithContextFields(
+					listener.server.logger.WithTraceFields(
 						common.LogFields{"message": message}).Debug("Fragmentor")
 						common.LogFields{"message": message}).Debug("Fragmentor")
 				},
 				},
 				conn)
 				conn)

+ 1 - 1
psiphon/common/tactics/tactics_test.go

@@ -851,7 +851,7 @@ func (l *testLogger) WithContext() common.LogContext {
 	return &testLoggerContext{context: stacktrace.GetParentFunctionName()}
 	return &testLoggerContext{context: stacktrace.GetParentFunctionName()}
 }
 }
 
 
-func (l *testLogger) WithContextFields(fields common.LogFields) common.LogContext {
+func (l *testLogger) WithTraceFields(fields common.LogFields) common.LogContext {
 	return &testLoggerContext{
 	return &testLoggerContext{
 		context: stacktrace.GetParentFunctionName(),
 		context: stacktrace.GetParentFunctionName(),
 		fields:  fields,
 		fields:  fields,

+ 19 - 19
psiphon/common/tun/tun.go

@@ -282,7 +282,7 @@ func NewServer(config *ServerConfig) (*Server, error) {
 // Start starts a server and returns with it running.
 // Start starts a server and returns with it running.
 func (server *Server) Start() {
 func (server *Server) Start() {
 
 
-	server.config.Logger.WithContext().Info("starting")
+	server.config.Logger.WithTrace().Info("starting")
 
 
 	server.workers.Add(1)
 	server.workers.Add(1)
 	go server.runSessionReaper()
 	go server.runSessionReaper()
@@ -297,7 +297,7 @@ func (server *Server) Start() {
 // Stop halts a running server.
 // Stop halts a running server.
 func (server *Server) Stop() {
 func (server *Server) Stop() {
 
 
-	server.config.Logger.WithContext().Info("stopping")
+	server.config.Logger.WithTrace().Info("stopping")
 
 
 	server.stopRunning()
 	server.stopRunning()
 
 
@@ -322,7 +322,7 @@ func (server *Server) Stop() {
 
 
 	server.workers.Wait()
 	server.workers.Wait()
 
 
-	server.config.Logger.WithContext().Info("stopped")
+	server.config.Logger.WithTrace().Info("stopped")
 }
 }
 
 
 // AllowedPortChecker is a function which returns true when it is
 // AllowedPortChecker is a function which returns true when it is
@@ -404,7 +404,7 @@ func (server *Server) ClientConnected(
 	default:
 	default:
 	}
 	}
 
 
-	server.config.Logger.WithContextFields(
+	server.config.Logger.WithTraceFields(
 		common.LogFields{"sessionID": sessionID}).Debug("client connected")
 		common.LogFields{"sessionID": sessionID}).Debug("client connected")
 
 
 	MTU := getMTU(server.config.MTU)
 	MTU := getMTU(server.config.MTU)
@@ -480,7 +480,7 @@ func (server *Server) ClientDisconnected(sessionID string) {
 	session := server.getSession(sessionID)
 	session := server.getSession(sessionID)
 	if session != nil {
 	if session != nil {
 
 
-		server.config.Logger.WithContextFields(
+		server.config.Logger.WithTraceFields(
 			common.LogFields{"sessionID": sessionID}).Debug("client disconnected")
 			common.LogFields{"sessionID": sessionID}).Debug("client disconnected")
 
 
 		server.interruptSession(session)
 		server.interruptSession(session)
@@ -494,7 +494,7 @@ func (server *Server) getSession(sessionID string) *session {
 		if ok {
 		if ok {
 			return s.(*session)
 			return s.(*session)
 		}
 		}
-		server.config.Logger.WithContext().Warning("unexpected missing session")
+		server.config.Logger.WithTrace().Warning("unexpected missing session")
 	}
 	}
 	return nil
 	return nil
 }
 }
@@ -722,7 +722,7 @@ func (server *Server) runDeviceDownstream() {
 		}
 		}
 
 
 		if err != nil {
 		if err != nil {
-			server.config.Logger.WithContextFields(
+			server.config.Logger.WithTraceFields(
 				common.LogFields{"error": err}).Warning("read device packet failed")
 				common.LogFields{"error": err}).Warning("read device packet failed")
 			// May be temporary error condition, keep reading.
 			// May be temporary error condition, keep reading.
 			continue
 			continue
@@ -826,7 +826,7 @@ func (server *Server) runClientUpstream(session *session) {
 		if err != nil {
 		if err != nil {
 
 
 			// Debug since channel I/O errors occur during normal operation.
 			// Debug since channel I/O errors occur during normal operation.
-			server.config.Logger.WithContextFields(
+			server.config.Logger.WithTraceFields(
 				common.LogFields{"error": err}).Debug("read channel packet failed")
 				common.LogFields{"error": err}).Debug("read channel packet failed")
 
 
 			// Tear down the session. Must be invoked asynchronously.
 			// Tear down the session. Must be invoked asynchronously.
@@ -860,7 +860,7 @@ func (server *Server) runClientUpstream(session *session) {
 		err = server.device.WritePacket(readPacket)
 		err = server.device.WritePacket(readPacket)
 
 
 		if err != nil {
 		if err != nil {
-			server.config.Logger.WithContextFields(
+			server.config.Logger.WithTraceFields(
 				common.LogFields{"error": err}).Warning("write device packet failed")
 				common.LogFields{"error": err}).Warning("write device packet failed")
 			// May be temporary error condition, keep working. The packet is
 			// May be temporary error condition, keep working. The packet is
 			// most likely dropped.
 			// most likely dropped.
@@ -891,7 +891,7 @@ func (server *Server) runClientDownstream(session *session) {
 		if err != nil {
 		if err != nil {
 
 
 			// Debug since channel I/O errors occur during normal operation.
 			// Debug since channel I/O errors occur during normal operation.
-			server.config.Logger.WithContextFields(
+			server.config.Logger.WithTraceFields(
 				common.LogFields{"error": err}).Debug("write channel packets failed")
 				common.LogFields{"error": err}).Debug("write channel packets failed")
 
 
 			downstreamPackets.Replace(packetBuffer)
 			downstreamPackets.Replace(packetBuffer)
@@ -998,14 +998,14 @@ func (server *Server) resetRouting(IPv4Address, IPv6Address net.IP) {
 
 
 	err := resetNATTables(server.config, IPv4Address)
 	err := resetNATTables(server.config, IPv4Address)
 	if err != nil {
 	if err != nil {
-		server.config.Logger.WithContextFields(
+		server.config.Logger.WithTraceFields(
 			common.LogFields{"error": err}).Warning("reset IPv4 routing failed")
 			common.LogFields{"error": err}).Warning("reset IPv4 routing failed")
 
 
 	}
 	}
 
 
 	err = resetNATTables(server.config, IPv6Address)
 	err = resetNATTables(server.config, IPv6Address)
 	if err != nil {
 	if err != nil {
-		server.config.Logger.WithContextFields(
+		server.config.Logger.WithTraceFields(
 			common.LogFields{"error": err}).Warning("reset IPv6 routing failed")
 			common.LogFields{"error": err}).Warning("reset IPv6 routing failed")
 
 
 	}
 	}
@@ -1755,7 +1755,7 @@ func NewClient(config *ClientConfig) (*Client, error) {
 // Start starts a client and returns with it running.
 // Start starts a client and returns with it running.
 func (client *Client) Start() {
 func (client *Client) Start() {
 
 
-	client.config.Logger.WithContext().Info("starting")
+	client.config.Logger.WithTrace().Info("starting")
 
 
 	client.workers.Add(1)
 	client.workers.Add(1)
 	go func() {
 	go func() {
@@ -1771,7 +1771,7 @@ func (client *Client) Start() {
 			}
 			}
 
 
 			if err != nil {
 			if err != nil {
-				client.config.Logger.WithContextFields(
+				client.config.Logger.WithTraceFields(
 					common.LogFields{"error": err}).Info("read device packet failed")
 					common.LogFields{"error": err}).Info("read device packet failed")
 				// May be temporary error condition, keep working.
 				// May be temporary error condition, keep working.
 				continue
 				continue
@@ -1817,7 +1817,7 @@ func (client *Client) Start() {
 			client.upstreamPackets.Replace(packetBuffer)
 			client.upstreamPackets.Replace(packetBuffer)
 
 
 			if err != nil {
 			if err != nil {
-				client.config.Logger.WithContextFields(
+				client.config.Logger.WithTraceFields(
 					common.LogFields{"error": err}).Info("write channel packets failed")
 					common.LogFields{"error": err}).Info("write channel packets failed")
 				// May be temporary error condition, such as reconnecting the tunnel;
 				// May be temporary error condition, such as reconnecting the tunnel;
 				// keep working. The packets are most likely dropped.
 				// keep working. The packets are most likely dropped.
@@ -1840,7 +1840,7 @@ func (client *Client) Start() {
 			}
 			}
 
 
 			if err != nil {
 			if err != nil {
-				client.config.Logger.WithContextFields(
+				client.config.Logger.WithTraceFields(
 					common.LogFields{"error": err}).Info("read channel packet failed")
 					common.LogFields{"error": err}).Info("read channel packet failed")
 				// May be temporary error condition, such as reconnecting the tunnel;
 				// May be temporary error condition, such as reconnecting the tunnel;
 				// keep working.
 				// keep working.
@@ -1858,7 +1858,7 @@ func (client *Client) Start() {
 			err = client.device.WritePacket(readPacket)
 			err = client.device.WritePacket(readPacket)
 
 
 			if err != nil {
 			if err != nil {
-				client.config.Logger.WithContextFields(
+				client.config.Logger.WithTraceFields(
 					common.LogFields{"error": err}).Info("write device packet failed")
 					common.LogFields{"error": err}).Info("write device packet failed")
 				// May be temporary error condition, keep working. The packet is
 				// May be temporary error condition, keep working. The packet is
 				// most likely dropped.
 				// most likely dropped.
@@ -1871,7 +1871,7 @@ func (client *Client) Start() {
 // Stop halts a running client.
 // Stop halts a running client.
 func (client *Client) Stop() {
 func (client *Client) Stop() {
 
 
-	client.config.Logger.WithContext().Info("stopping")
+	client.config.Logger.WithTrace().Info("stopping")
 
 
 	client.stopRunning()
 	client.stopRunning()
 	client.device.Close()
 	client.device.Close()
@@ -1882,7 +1882,7 @@ func (client *Client) Stop() {
 	client.metrics.checkpoint(
 	client.metrics.checkpoint(
 		client.config.Logger, nil, "packet_metrics", packetMetricsAll)
 		client.config.Logger, nil, "packet_metrics", packetMetricsAll)
 
 
-	client.config.Logger.WithContext().Info("stopped")
+	client.config.Logger.WithTrace().Info("stopped")
 }
 }
 
 
 /*
 /*

+ 1 - 1
psiphon/common/tun/tun_darwin.go

@@ -354,7 +354,7 @@ func configureServerInterface(
 
 
 	tempFile.Close()
 	tempFile.Close()
 
 
-	config.Logger.WithContextFields(common.LogFields{
+	config.Logger.WithTraceFields(common.LogFields{
 		"content": pfConf,
 		"content": pfConf,
 	}).Debug("pf.conf")
 	}).Debug("pf.conf")
 
 

+ 5 - 5
psiphon/common/tun/tun_linux.go

@@ -235,7 +235,7 @@ func configureServerInterface(
 		"add", serverIPv6AddressCIDR)
 		"add", serverIPv6AddressCIDR)
 	if err != nil {
 	if err != nil {
 		if config.AllowNoIPv6NetworkConfiguration {
 		if config.AllowNoIPv6NetworkConfiguration {
-			config.Logger.WithContextFields(
+			config.Logger.WithTraceFields(
 				common.LogFields{
 				common.LogFields{
 					"error": err}).Warning(
 					"error": err}).Warning(
 				"assign IPv6 address failed")
 				"assign IPv6 address failed")
@@ -269,7 +269,7 @@ func configureServerInterface(
 		"net.ipv6.conf.all.forwarding=1")
 		"net.ipv6.conf.all.forwarding=1")
 	if err != nil {
 	if err != nil {
 		if config.AllowNoIPv6NetworkConfiguration {
 		if config.AllowNoIPv6NetworkConfiguration {
-			config.Logger.WithContextFields(
+			config.Logger.WithTraceFields(
 				common.LogFields{
 				common.LogFields{
 					"error": err}).Warning(
 					"error": err}).Warning(
 				"allow IPv6 forwarding failed")
 				"allow IPv6 forwarding failed")
@@ -306,7 +306,7 @@ func configureServerInterface(
 			"-j", "MASQUERADE")
 			"-j", "MASQUERADE")
 		if mode != "-D" && err != nil {
 		if mode != "-D" && err != nil {
 			if config.AllowNoIPv6NetworkConfiguration {
 			if config.AllowNoIPv6NetworkConfiguration {
-				config.Logger.WithContextFields(
+				config.Logger.WithTraceFields(
 					common.LogFields{
 					common.LogFields{
 						"error": err}).Warning(
 						"error": err}).Warning(
 					"configure IPv6 masquerading failed")
 					"configure IPv6 masquerading failed")
@@ -351,7 +351,7 @@ func configureClientInterface(
 		"add", config.IPv6AddressCIDR)
 		"add", config.IPv6AddressCIDR)
 	if err != nil {
 	if err != nil {
 		if config.AllowNoIPv6NetworkConfiguration {
 		if config.AllowNoIPv6NetworkConfiguration {
-			config.Logger.WithContextFields(
+			config.Logger.WithTraceFields(
 				common.LogFields{
 				common.LogFields{
 					"error": err}).Warning(
 					"error": err}).Warning(
 				"assign IPv6 address failed")
 				"assign IPv6 address failed")
@@ -394,7 +394,7 @@ func configureClientInterface(
 			"dev", tunDeviceName)
 			"dev", tunDeviceName)
 		if err != nil {
 		if err != nil {
 			if config.AllowNoIPv6NetworkConfiguration {
 			if config.AllowNoIPv6NetworkConfiguration {
-				config.Logger.WithContextFields(
+				config.Logger.WithTraceFields(
 					common.LogFields{
 					common.LogFields{
 						"error": err}).Warning("add IPv6 route failed")
 						"error": err}).Warning("add IPv6 route failed")
 			} else {
 			} else {

+ 1 - 1
psiphon/common/tun/tun_test.go

@@ -704,7 +704,7 @@ func (logger *testLogger) WithContext() common.LogContext {
 	return &testLoggerContext{context: stacktrace.GetParentFunctionName()}
 	return &testLoggerContext{context: stacktrace.GetParentFunctionName()}
 }
 }
 
 
-func (logger *testLogger) WithContextFields(fields common.LogFields) common.LogContext {
+func (logger *testLogger) WithTraceFields(fields common.LogFields) common.LogContext {
 	return &testLoggerContext{
 	return &testLoggerContext{
 		context: stacktrace.GetParentFunctionName(),
 		context: stacktrace.GetParentFunctionName(),
 		fields:  fields,
 		fields:  fields,

+ 1 - 1
psiphon/common/tun/utils.go

@@ -62,7 +62,7 @@ func runNetworkConfigCommand(
 	cmd := exec.Command(commandName, commandArgs...)
 	cmd := exec.Command(commandName, commandArgs...)
 	output, err := cmd.CombinedOutput()
 	output, err := cmd.CombinedOutput()
 
 
-	logger.WithContextFields(common.LogFields{
+	logger.WithTraceFields(common.LogFields{
 		"command": commandName,
 		"command": commandName,
 		"args":    commandArgs,
 		"args":    commandArgs,
 		"output":  string(output),
 		"output":  string(output),

+ 20 - 20
psiphon/notice.go

@@ -1002,16 +1002,16 @@ func NoticeCommonLogger() common.Logger {
 type commonLogger struct {
 type commonLogger struct {
 }
 }
 
 
-func (logger *commonLogger) WithContext() common.LogContext {
-	return &commonLogContext{
-		context: stacktrace.GetParentFunctionName(),
+func (logger *commonLogger) WithTrace() common.LogTrace {
+	return &commonLogTrace{
+		trace: stacktrace.GetParentFunctionName(),
 	}
 	}
 }
 }
 
 
-func (logger *commonLogger) WithContextFields(fields common.LogFields) common.LogContext {
-	return &commonLogContext{
-		context: stacktrace.GetParentFunctionName(),
-		fields:  fields,
+func (logger *commonLogger) WithTraceFields(fields common.LogFields) common.LogTrace {
+	return &commonLogTrace{
+		trace:  stacktrace.GetParentFunctionName(),
+		fields: fields,
 	}
 	}
 }
 }
 
 
@@ -1035,12 +1035,12 @@ func listCommonFields(fields common.LogFields) []interface{} {
 	return fieldList
 	return fieldList
 }
 }
 
 
-type commonLogContext struct {
-	context string
-	fields  common.LogFields
+type commonLogTrace struct {
+	trace  string
+	fields common.LogFields
 }
 }
 
 
-func (context *commonLogContext) outputNotice(
+func (log *commonLogTrace) outputNotice(
 	noticeType string, args ...interface{}) {
 	noticeType string, args ...interface{}) {
 
 
 	singletonNoticeLogger.outputNotice(
 	singletonNoticeLogger.outputNotice(
@@ -1048,22 +1048,22 @@ func (context *commonLogContext) outputNotice(
 		append(
 		append(
 			[]interface{}{
 			[]interface{}{
 				"message", fmt.Sprint(args...),
 				"message", fmt.Sprint(args...),
-				"context", context.context},
-			listCommonFields(context.fields)...)...)
+				"trace", log.trace},
+			listCommonFields(log.fields)...)...)
 }
 }
 
 
-func (context *commonLogContext) Debug(args ...interface{}) {
+func (log *commonLogTrace) Debug(args ...interface{}) {
 	// Ignored.
 	// Ignored.
 }
 }
 
 
-func (context *commonLogContext) Info(args ...interface{}) {
-	context.outputNotice("Info", args...)
+func (log *commonLogTrace) Info(args ...interface{}) {
+	log.outputNotice("Info", args...)
 }
 }
 
 
-func (context *commonLogContext) Warning(args ...interface{}) {
-	context.outputNotice("Alert", args...)
+func (log *commonLogTrace) Warning(args ...interface{}) {
+	log.outputNotice("Alert", args...)
 }
 }
 
 
-func (context *commonLogContext) Error(args ...interface{}) {
-	context.outputNotice("Error", args...)
+func (log *commonLogTrace) Error(args ...interface{}) {
+	log.outputNotice("Error", args...)
 }
 }

+ 1 - 1
psiphon/server/api.go

@@ -280,7 +280,7 @@ func handshakeAPIRequestHandler(
 	// common API parameters and "handshake_completed" flag, this handshake
 	// common API parameters and "handshake_completed" flag, this handshake
 	// log is mostly redundant and set to debug level.
 	// log is mostly redundant and set to debug level.
 
 
-	log.WithContextFields(
+	log.WithTraceFields(
 		getRequestLogFields(
 		getRequestLogFields(
 			"",
 			"",
 			geoIPData,
 			geoIPData,

+ 3 - 3
psiphon/server/dns.go

@@ -89,7 +89,7 @@ func NewDNSResolver(defaultResolver string) (*DNSResolver, error) {
 
 
 			dns.resolvers = resolvers
 			dns.resolvers = resolvers
 
 
-			log.WithContextFields(
+			log.WithTraceFields(
 				LogFields{
 				LogFields{
 					"resolvers": resolvers,
 					"resolvers": resolvers,
 				}).Debug("loaded system DNS resolvers")
 				}).Debug("loaded system DNS resolvers")
@@ -103,7 +103,7 @@ func NewDNSResolver(defaultResolver string) (*DNSResolver, error) {
 			return nil, errors.Trace(err)
 			return nil, errors.Trace(err)
 		}
 		}
 
 
-		log.WithContextFields(
+		log.WithTraceFields(
 			LogFields{"err": err}).Info(
 			LogFields{"err": err}).Info(
 			"failed to load system DNS resolver; using default")
 			"failed to load system DNS resolver; using default")
 
 
@@ -162,7 +162,7 @@ func (dns *DNSResolver) reloadWhenStale() {
 
 
 			_, err := dns.Reload()
 			_, err := dns.Reload()
 			if err != nil {
 			if err != nil {
-				log.WithContextFields(
+				log.WithTraceFields(
 					LogFields{"err": err}).Info(
 					LogFields{"err": err}).Info(
 					"failed to reload system DNS resolver")
 					"failed to reload system DNS resolver")
 			}
 			}

+ 1 - 1
psiphon/server/geoip.go

@@ -205,7 +205,7 @@ func (geoIP *GeoIPService) Lookup(ipAddress string) GeoIPData {
 		err := database.maxMindReader.Lookup(ip, &geoIPFields)
 		err := database.maxMindReader.Lookup(ip, &geoIPFields)
 		database.ReloadableFile.RUnlock()
 		database.ReloadableFile.RUnlock()
 		if err != nil {
 		if err != nil {
-			log.WithContextFields(LogFields{"error": err}).Warning("GeoIP lookup failed")
+			log.WithTraceFields(LogFields{"error": err}).Warning("GeoIP lookup failed")
 		}
 		}
 	}
 	}
 
 

+ 42 - 43
psiphon/server/log.go

@@ -38,32 +38,32 @@ import (
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
 )
 )
 
 
-// ContextLogger adds context logging functionality to the
-// underlying logging packages.
-type ContextLogger struct {
+// TraceLogger adds single frame stack trace information to the underlying
+// logging facilities.
+type TraceLogger struct {
 	*logrus.Logger
 	*logrus.Logger
 }
 }
 
 
-// LogFields is an alias for the field struct in the
-// underlying logging package.
+// LogFields is an alias for the field struct in the underlying logging
+// package.
 type LogFields logrus.Fields
 type LogFields logrus.Fields
 
 
-// WithContext adds a "context" field containing the caller's
-// function name and source file line number; and "host_id" and
-// "build_rev" fields identifying this server and build.
-// Use this function when the log has no fields.
-func (logger *ContextLogger) WithContext() *logrus.Entry {
+// WithTrace adds a "trace" field containing the caller's function name
+// and source file line number; and "host_id" and "build_rev" fields
+// identifying this server and build. Use this function when the log has no
+// fields.
+func (logger *TraceLogger) WithTrace() *logrus.Entry {
 	return logger.WithFields(
 	return logger.WithFields(
 		logrus.Fields{
 		logrus.Fields{
-			"context":   stacktrace.GetParentFunctionName(),
+			"trace":     stacktrace.GetParentFunctionName(),
 			"host_id":   logHostID,
 			"host_id":   logHostID,
 			"build_rev": logBuildRev,
 			"build_rev": logBuildRev,
 		})
 		})
 }
 }
 
 
 func renameLogFields(fields LogFields) {
 func renameLogFields(fields LogFields) {
-	if _, ok := fields["context"]; ok {
-		fields["fields.context"] = fields["context"]
+	if _, ok := fields["trace"]; ok {
+		fields["fields.trace"] = fields["trace"]
 	}
 	}
 	if _, ok := fields["host_id"]; ok {
 	if _, ok := fields["host_id"]; ok {
 		fields["fields.host_id"] = fields["host_id"]
 		fields["fields.host_id"] = fields["host_id"]
@@ -73,15 +73,14 @@ func renameLogFields(fields LogFields) {
 	}
 	}
 }
 }
 
 
-// WithContextFields adds a "context" field containing the caller's
-// function name and source file line number; and "host_id" and
-// "build_rev" fields identifying this server and build.
-// Use this function when the log has fields.
-// Note that any existing "context"/"host_id"/"build_rev" field will
-// be renamed to "field.<name>".
-func (logger *ContextLogger) WithContextFields(fields LogFields) *logrus.Entry {
+// WithTraceFields adds a "trace" field containing the caller's function name
+// and source file line number; and "host_id" and "build_rev" fields
+// identifying this server and build. Use this function when the log has
+// fields. Note that any existing "trace"/"host_id"/"build_rev" field will be
+// renamed to "field.<name>".
+func (logger *TraceLogger) WithTraceFields(fields LogFields) *logrus.Entry {
 	renameLogFields(fields)
 	renameLogFields(fields)
-	fields["context"] = stacktrace.GetParentFunctionName()
+	fields["trace"] = stacktrace.GetParentFunctionName()
 	fields["host_id"] = logHostID
 	fields["host_id"] = logHostID
 	fields["build_rev"] = logBuildRev
 	fields["build_rev"] = logBuildRev
 	return logger.WithFields(logrus.Fields(fields))
 	return logger.WithFields(logrus.Fields(fields))
@@ -94,9 +93,9 @@ func (logger *ContextLogger) WithContextFields(fields LogFields) *logrus.Entry {
 // support API logs which have neither a natural message nor severity; and
 // support API logs which have neither a natural message nor severity; and
 // omitting these values here makes it easier to ship these logs to existing
 // omitting these values here makes it easier to ship these logs to existing
 // API log consumers.
 // API log consumers.
-// Note that any existing "context"/"host_id"/"build_rev" field will
-// be renamed to "field.<name>".
-func (logger *ContextLogger) LogRawFieldsWithTimestamp(fields LogFields) {
+// Note that any existing "trace"/"host_id"/"build_rev" field will be renamed
+// to "field.<name>".
+func (logger *TraceLogger) LogRawFieldsWithTimestamp(fields LogFields) {
 	renameLogFields(fields)
 	renameLogFields(fields)
 	fields["host_id"] = logHostID
 	fields["host_id"] = logHostID
 	fields["build_rev"] = logBuildRev
 	fields["build_rev"] = logBuildRev
@@ -106,7 +105,7 @@ func (logger *ContextLogger) LogRawFieldsWithTimestamp(fields LogFields) {
 
 
 // LogPanicRecover calls LogRawFieldsWithTimestamp with standard fields
 // LogPanicRecover calls LogRawFieldsWithTimestamp with standard fields
 // for logging recovered panics.
 // for logging recovered panics.
-func (logger *ContextLogger) LogPanicRecover(recoverValue interface{}, stack []byte) {
+func (logger *TraceLogger) LogPanicRecover(recoverValue interface{}, stack []byte) {
 	log.LogRawFieldsWithTimestamp(
 	log.LogRawFieldsWithTimestamp(
 		LogFields{
 		LogFields{
 			"event_name":    "panic",
 			"event_name":    "panic",
@@ -116,32 +115,32 @@ func (logger *ContextLogger) LogPanicRecover(recoverValue interface{}, stack []b
 }
 }
 
 
 type commonLogger struct {
 type commonLogger struct {
-	contextLogger *ContextLogger
+	traceLogger *TraceLogger
 }
 }
 
 
-func (logger *commonLogger) WithContext() common.LogContext {
-	// Patch context to be correct parent
-	return logger.contextLogger.WithContext().WithField(
-		"context", stacktrace.GetParentFunctionName())
+func (logger *commonLogger) WithTrace() common.LogTrace {
+	// Patch trace to be correct parent
+	return logger.traceLogger.WithTrace().WithField(
+		"trace", stacktrace.GetParentFunctionName())
 }
 }
 
 
-func (logger *commonLogger) WithContextFields(fields common.LogFields) common.LogContext {
-	// Patch context to be correct parent
-	return logger.contextLogger.WithContextFields(LogFields(fields)).WithField(
-		"context", stacktrace.GetParentFunctionName())
+func (logger *commonLogger) WithTraceFields(fields common.LogFields) common.LogTrace {
+	// Patch trace to be correct parent
+	return logger.traceLogger.WithTraceFields(LogFields(fields)).WithField(
+		"trace", stacktrace.GetParentFunctionName())
 }
 }
 
 
 func (logger *commonLogger) LogMetric(metric string, fields common.LogFields) {
 func (logger *commonLogger) LogMetric(metric string, fields common.LogFields) {
 	fields["event_name"] = metric
 	fields["event_name"] = metric
-	logger.contextLogger.LogRawFieldsWithTimestamp(LogFields(fields))
+	logger.traceLogger.LogRawFieldsWithTimestamp(LogFields(fields))
 }
 }
 
 
-// CommonLogger wraps a ContextLogger instance with an interface
-// that conforms to common.Logger. This is used to make the ContextLogger
-// available to other packages that don't import the "server" package.
-func CommonLogger(contextLogger *ContextLogger) *commonLogger {
+// CommonLogger wraps a TraceLogger instance with an interface that conforms
+// to common.Logger. This is used to make the TraceLogger available to other
+// packages that don't import the "server" package.
+func CommonLogger(traceLogger *TraceLogger) *commonLogger {
 	return &commonLogger{
 	return &commonLogger{
-		contextLogger: contextLogger,
+		traceLogger: traceLogger,
 	}
 	}
 }
 }
 
 
@@ -226,7 +225,7 @@ func (f *CustomJSONFormatter) Format(entry *logrus.Entry) ([]byte, error) {
 	return append(serialized, '\n'), nil
 	return append(serialized, '\n'), nil
 }
 }
 
 
-var log *ContextLogger
+var log *TraceLogger
 var logHostID, logBuildRev string
 var logHostID, logBuildRev string
 var initLogging sync.Once
 var initLogging sync.Once
 
 
@@ -289,7 +288,7 @@ func InitLogging(config *Config) (retErr error) {
 			logWriter = os.Stderr
 			logWriter = os.Stderr
 		}
 		}
 
 
-		log = &ContextLogger{
+		log = &TraceLogger{
 			&logrus.Logger{
 			&logrus.Logger{
 				Out:       logWriter,
 				Out:       logWriter,
 				Formatter: &CustomJSONFormatter{},
 				Formatter: &CustomJSONFormatter{},
@@ -308,7 +307,7 @@ func init() {
 	// "http: TLS handshake error from <client-ip-addr>:<port>: [...]: i/o timeout"
 	// "http: TLS handshake error from <client-ip-addr>:<port>: [...]: i/o timeout"
 	go_log.SetOutput(ioutil.Discard)
 	go_log.SetOutput(ioutil.Discard)
 
 
-	log = &ContextLogger{
+	log = &TraceLogger{
 		&logrus.Logger{
 		&logrus.Logger{
 			Out:       os.Stderr,
 			Out:       os.Stderr,
 			Formatter: &CustomJSONFormatter{},
 			Formatter: &CustomJSONFormatter{},

+ 7 - 7
psiphon/server/meek.go

@@ -257,7 +257,7 @@ func (server *MeekServer) ServeHTTP(responseWriter http.ResponseWriter, request
 		break
 		break
 	}
 	}
 	if meekCookie == nil || len(meekCookie.Value) == 0 {
 	if meekCookie == nil || len(meekCookie.Value) == 0 {
-		log.WithContext().Warning("missing meek cookie")
+		log.WithTrace().Warning("missing meek cookie")
 		common.TerminateHTTPConnection(responseWriter, request)
 		common.TerminateHTTPConnection(responseWriter, request)
 		return
 		return
 	}
 	}
@@ -266,7 +266,7 @@ func (server *MeekServer) ServeHTTP(responseWriter http.ResponseWriter, request
 		for _, header := range server.support.Config.MeekProhibitedHeaders {
 		for _, header := range server.support.Config.MeekProhibitedHeaders {
 			value := request.Header.Get(header)
 			value := request.Header.Get(header)
 			if header != "" {
 			if header != "" {
-				log.WithContextFields(LogFields{
+				log.WithTraceFields(LogFields{
 					"header": header,
 					"header": header,
 					"value":  value,
 					"value":  value,
 				}).Warning("prohibited meek header")
 				}).Warning("prohibited meek header")
@@ -290,7 +290,7 @@ func (server *MeekServer) ServeHTTP(responseWriter http.ResponseWriter, request
 	if err != nil {
 	if err != nil {
 		// Debug since session cookie errors commonly occur during
 		// Debug since session cookie errors commonly occur during
 		// normal operation.
 		// normal operation.
-		log.WithContextFields(LogFields{"error": err}).Debug("session lookup failed")
+		log.WithTraceFields(LogFields{"error": err}).Debug("session lookup failed")
 		common.TerminateHTTPConnection(responseWriter, request)
 		common.TerminateHTTPConnection(responseWriter, request)
 		return
 		return
 	}
 	}
@@ -304,7 +304,7 @@ func (server *MeekServer) ServeHTTP(responseWriter http.ResponseWriter, request
 		handled := server.support.TacticsServer.HandleEndPoint(
 		handled := server.support.TacticsServer.HandleEndPoint(
 			endPoint, common.GeoIPData(geoIPData), responseWriter, request)
 			endPoint, common.GeoIPData(geoIPData), responseWriter, request)
 		if !handled {
 		if !handled {
-			log.WithContextFields(LogFields{"endPoint": endPoint}).Info("unhandled endpoint")
+			log.WithTraceFields(LogFields{"endPoint": endPoint}).Info("unhandled endpoint")
 			common.TerminateHTTPConnection(responseWriter, request)
 			common.TerminateHTTPConnection(responseWriter, request)
 		}
 		}
 		return
 		return
@@ -363,7 +363,7 @@ func (server *MeekServer) ServeHTTP(responseWriter http.ResponseWriter, request
 		if err != io.EOF {
 		if err != io.EOF {
 			// Debug since errors such as "i/o timeout" occur during normal operation;
 			// Debug since errors such as "i/o timeout" occur during normal operation;
 			// also, golang network error messages may contain client IP.
 			// also, golang network error messages may contain client IP.
-			log.WithContextFields(LogFields{"error": err}).Debug("read request failed")
+			log.WithTraceFields(LogFields{"error": err}).Debug("read request failed")
 		}
 		}
 		common.TerminateHTTPConnection(responseWriter, request)
 		common.TerminateHTTPConnection(responseWriter, request)
 
 
@@ -474,7 +474,7 @@ func (server *MeekServer) ServeHTTP(responseWriter http.ResponseWriter, request
 		if responseError != io.EOF {
 		if responseError != io.EOF {
 			// Debug since errors such as "i/o timeout" occur during normal operation;
 			// Debug since errors such as "i/o timeout" occur during normal operation;
 			// also, golang network error messages may contain client IP.
 			// also, golang network error messages may contain client IP.
-			log.WithContextFields(LogFields{"error": responseError}).Debug("write response failed")
+			log.WithTraceFields(LogFields{"error": responseError}).Debug("write response failed")
 		}
 		}
 		common.TerminateHTTPConnection(responseWriter, request)
 		common.TerminateHTTPConnection(responseWriter, request)
 
 
@@ -835,7 +835,7 @@ func (server *MeekServer) deleteExpiredSessions() {
 	}
 	}
 	deleteWaitGroup.Wait()
 	deleteWaitGroup.Wait()
 
 
-	log.WithContextFields(
+	log.WithTraceFields(
 		LogFields{"elapsed time": monotime.Since(start)}).Debug("deleted expired sessions")
 		LogFields{"elapsed time": monotime.Since(start)}).Debug("deleted expired sessions")
 }
 }
 
 

+ 11 - 11
psiphon/server/services.go

@@ -51,23 +51,23 @@ func RunServices(configJSON []byte) error {
 
 
 	config, err := LoadConfig(configJSON)
 	config, err := LoadConfig(configJSON)
 	if err != nil {
 	if err != nil {
-		log.WithContextFields(LogFields{"error": err}).Error("load config failed")
+		log.WithTraceFields(LogFields{"error": err}).Error("load config failed")
 		return errors.Trace(err)
 		return errors.Trace(err)
 	}
 	}
 
 
 	err = InitLogging(config)
 	err = InitLogging(config)
 	if err != nil {
 	if err != nil {
-		log.WithContextFields(LogFields{"error": err}).Error("init logging failed")
+		log.WithTraceFields(LogFields{"error": err}).Error("init logging failed")
 		return errors.Trace(err)
 		return errors.Trace(err)
 	}
 	}
 
 
 	supportServices, err := NewSupportServices(config)
 	supportServices, err := NewSupportServices(config)
 	if err != nil {
 	if err != nil {
-		log.WithContextFields(LogFields{"error": err}).Error("init support services failed")
+		log.WithTraceFields(LogFields{"error": err}).Error("init support services failed")
 		return errors.Trace(err)
 		return errors.Trace(err)
 	}
 	}
 
 
-	log.WithContextFields(*buildinfo.GetBuildInfo().ToMap()).Info("startup")
+	log.WithTraceFields(*buildinfo.GetBuildInfo().ToMap()).Info("startup")
 
 
 	waitGroup := new(sync.WaitGroup)
 	waitGroup := new(sync.WaitGroup)
 	shutdownBroadcast := make(chan struct{})
 	shutdownBroadcast := make(chan struct{})
@@ -75,7 +75,7 @@ func RunServices(configJSON []byte) error {
 
 
 	tunnelServer, err := NewTunnelServer(supportServices, shutdownBroadcast)
 	tunnelServer, err := NewTunnelServer(supportServices, shutdownBroadcast)
 	if err != nil {
 	if err != nil {
-		log.WithContextFields(LogFields{"error": err}).Error("init tunnel server failed")
+		log.WithTraceFields(LogFields{"error": err}).Error("init tunnel server failed")
 		return errors.Trace(err)
 		return errors.Trace(err)
 	}
 	}
 
 
@@ -93,7 +93,7 @@ func RunServices(configJSON []byte) error {
 			SessionIdleExpirySeconds:    config.PacketTunnelSessionIdleExpirySeconds,
 			SessionIdleExpirySeconds:    config.PacketTunnelSessionIdleExpirySeconds,
 		})
 		})
 		if err != nil {
 		if err != nil {
-			log.WithContextFields(LogFields{"error": err}).Error("init packet tunnel failed")
+			log.WithTraceFields(LogFields{"error": err}).Error("init packet tunnel failed")
 			return errors.Trace(err)
 			return errors.Trace(err)
 		}
 		}
 
 
@@ -238,11 +238,11 @@ loop:
 			logServerLoad(tunnelServer)
 			logServerLoad(tunnelServer)
 
 
 		case <-systemStopSignal:
 		case <-systemStopSignal:
-			log.WithContext().Info("shutdown by system")
+			log.WithTrace().Info("shutdown by system")
 			break loop
 			break loop
 
 
 		case err = <-errorChannel:
 		case err = <-errorChannel:
-			log.WithContextFields(LogFields{"error": err}).Error("service failed")
+			log.WithTraceFields(LogFields{"error": err}).Error("service failed")
 			break loop
 			break loop
 		}
 		}
 	}
 	}
@@ -301,7 +301,7 @@ func getRuntimeMetrics() LogFields {
 
 
 func outputProcessProfiles(config *Config, filenameSuffix string) {
 func outputProcessProfiles(config *Config, filenameSuffix string) {
 
 
-	log.WithContextFields(getRuntimeMetrics()).Info("runtime_metrics")
+	log.WithTraceFields(getRuntimeMetrics()).Info("runtime_metrics")
 
 
 	if config.ProcessProfileOutputDirectory != "" {
 	if config.ProcessProfileOutputDirectory != "" {
 		common.WriteRuntimeProfiles(
 		common.WriteRuntimeProfiles(
@@ -460,13 +460,13 @@ func (support *SupportServices) Reload() {
 		}
 		}
 
 
 		if err != nil {
 		if err != nil {
-			log.WithContextFields(
+			log.WithTraceFields(
 				LogFields{
 				LogFields{
 					"reloader": reloader.LogDescription(),
 					"reloader": reloader.LogDescription(),
 					"error":    err}).Error("reload failed")
 					"error":    err}).Error("reload failed")
 			// Keep running with previous state
 			// Keep running with previous state
 		} else {
 		} else {
-			log.WithContextFields(
+			log.WithTraceFields(
 				LogFields{
 				LogFields{
 					"reloader": reloader.LogDescription(),
 					"reloader": reloader.LogDescription(),
 					"reloaded": reloaded}).Info("reload success")
 					"reloaded": reloaded}).Info("reload success")

+ 3 - 3
psiphon/server/trafficRules.go

@@ -547,7 +547,7 @@ func (set *TrafficRulesSet) GetTrafficRules(
 	// TODO: faster lookup?
 	// TODO: faster lookup?
 	for _, filteredRules := range set.FilteredRules {
 	for _, filteredRules := range set.FilteredRules {
 
 
-		log.WithContextFields(LogFields{"filter": filteredRules.Filter}).Debug("filter check")
+		log.WithTraceFields(LogFields{"filter": filteredRules.Filter}).Debug("filter check")
 
 
 		if len(filteredRules.Filter.TunnelProtocols) > 0 {
 		if len(filteredRules.Filter.TunnelProtocols) > 0 {
 			if !common.Contains(filteredRules.Filter.TunnelProtocols, tunnelProtocol) {
 			if !common.Contains(filteredRules.Filter.TunnelProtocols, tunnelProtocol) {
@@ -629,7 +629,7 @@ func (set *TrafficRulesSet) GetTrafficRules(
 			}
 			}
 		}
 		}
 
 
-		log.WithContextFields(LogFields{"filter": filteredRules.Filter}).Debug("filter match")
+		log.WithTraceFields(LogFields{"filter": filteredRules.Filter}).Debug("filter match")
 
 
 		// This is the first match. Override defaults using provided fields from selected rules, and return result.
 		// This is the first match. Override defaults using provided fields from selected rules, and return result.
 
 
@@ -713,7 +713,7 @@ func (set *TrafficRulesSet) GetTrafficRules(
 		trafficRules.RateLimits.WriteUnthrottledBytes = new(int64)
 		trafficRules.RateLimits.WriteUnthrottledBytes = new(int64)
 	}
 	}
 
 
-	log.WithContextFields(LogFields{"trafficRules": trafficRules}).Debug("selected traffic rules")
+	log.WithTraceFields(LogFields{"trafficRules": trafficRules}).Debug("selected traffic rules")
 
 
 	return trafficRules
 	return trafficRules
 }
 }

+ 41 - 41
psiphon/server/tunnelServer.go

@@ -192,7 +192,7 @@ func (server *TunnelServer) Run() error {
 				return common.GeoIPData(support.GeoIPService.Lookup(IPAddress))
 				return common.GeoIPData(support.GeoIPService.Lookup(IPAddress))
 			})
 			})
 
 
-		log.WithContextFields(
+		log.WithTraceFields(
 			LogFields{
 			LogFields{
 				"localAddress":   localAddress,
 				"localAddress":   localAddress,
 				"tunnelProtocol": tunnelProtocol,
 				"tunnelProtocol": tunnelProtocol,
@@ -212,7 +212,7 @@ func (server *TunnelServer) Run() error {
 		go func(listener *sshListener) {
 		go func(listener *sshListener) {
 			defer server.runWaitGroup.Done()
 			defer server.runWaitGroup.Done()
 
 
-			log.WithContextFields(
+			log.WithTraceFields(
 				LogFields{
 				LogFields{
 					"localAddress":   listener.localAddress,
 					"localAddress":   listener.localAddress,
 					"tunnelProtocol": listener.tunnelProtocol,
 					"tunnelProtocol": listener.tunnelProtocol,
@@ -223,7 +223,7 @@ func (server *TunnelServer) Run() error {
 				server.listenerError,
 				server.listenerError,
 				listener.tunnelProtocol)
 				listener.tunnelProtocol)
 
 
-			log.WithContextFields(
+			log.WithTraceFields(
 				LogFields{
 				LogFields{
 					"localAddress":   listener.localAddress,
 					"localAddress":   listener.localAddress,
 					"tunnelProtocol": listener.tunnelProtocol,
 					"tunnelProtocol": listener.tunnelProtocol,
@@ -244,7 +244,7 @@ func (server *TunnelServer) Run() error {
 	server.sshServer.stopClients()
 	server.sshServer.stopClients()
 	server.runWaitGroup.Wait()
 	server.runWaitGroup.Wait()
 
 
-	log.WithContext().Info("stopped")
+	log.WithTrace().Info("stopped")
 
 
 	return err
 	return err
 }
 }
@@ -408,7 +408,7 @@ func (sshServer *sshServer) setEstablishTunnels(establish bool) {
 	}
 	}
 	atomic.StoreInt32(&sshServer.establishTunnels, establishFlag)
 	atomic.StoreInt32(&sshServer.establishTunnels, establishFlag)
 
 
-	log.WithContextFields(
+	log.WithTraceFields(
 		LogFields{"establish": establish}).Info("establishing tunnels")
 		LogFields{"establish": establish}).Info("establishing tunnels")
 }
 }
 
 
@@ -436,7 +436,7 @@ func (sshServer *sshServer) runListener(
 		// span multiple TCP connections.
 		// span multiple TCP connections.
 
 
 		if !sshServer.getEstablishTunnels() {
 		if !sshServer.getEstablishTunnels() {
-			log.WithContext().Debug("not establishing tunnels")
+			log.WithTrace().Debug("not establishing tunnels")
 			clientConn.Close()
 			clientConn.Close()
 			return
 			return
 		}
 		}
@@ -451,7 +451,7 @@ func (sshServer *sshServer) runListener(
 		if clientTunnelProtocol != "" {
 		if clientTunnelProtocol != "" {
 
 
 			if !common.Contains(runningProtocols, clientTunnelProtocol) {
 			if !common.Contains(runningProtocols, clientTunnelProtocol) {
-				log.WithContextFields(
+				log.WithTraceFields(
 					LogFields{
 					LogFields{
 						"clientTunnelProtocol": clientTunnelProtocol}).
 						"clientTunnelProtocol": clientTunnelProtocol}).
 					Warning("invalid client tunnel protocol")
 					Warning("invalid client tunnel protocol")
@@ -514,7 +514,7 @@ func (sshServer *sshServer) runListener(
 
 
 			if err != nil {
 			if err != nil {
 				if e, ok := err.(net.Error); ok && e.Temporary() {
 				if e, ok := err.(net.Error); ok && e.Temporary() {
-					log.WithContextFields(LogFields{"error": err}).Error("accept failed")
+					log.WithTraceFields(LogFields{"error": err}).Error("accept failed")
 					// Temporary error, keep running
 					// Temporary error, keep running
 					continue
 					continue
 				}
 				}
@@ -582,7 +582,7 @@ func (sshServer *sshServer) registerEstablishedClient(client *sshClient) bool {
 
 
 		// This case is expected to be common, and so logged at the lowest severity
 		// This case is expected to be common, and so logged at the lowest severity
 		// level.
 		// level.
-		log.WithContext().Debug(
+		log.WithTrace().Debug(
 			"stopping existing client with duplicate session ID")
 			"stopping existing client with duplicate session ID")
 
 
 		existingClient.stop()
 		existingClient.stop()
@@ -634,7 +634,7 @@ func (sshServer *sshServer) registerEstablishedClient(client *sshClient) bool {
 	if sshServer.clients[client.sessionID] != nil {
 	if sshServer.clients[client.sessionID] != nil {
 		// As this is expected to be rare case, it's logged at a higher severity
 		// As this is expected to be rare case, it's logged at a higher severity
 		// level.
 		// level.
-		log.WithContext().Warning(
+		log.WithTrace().Warning(
 			"aborting new client with duplicate session ID")
 			"aborting new client with duplicate session ID")
 		return false
 		return false
 	}
 	}
@@ -962,7 +962,7 @@ func (sshServer *sshServer) handleClient(tunnelProtocol string, clientConn net.C
 		if err != nil {
 		if err != nil {
 			clientConn.Close()
 			clientConn.Close()
 			// This is a debug log as the only possible error is context timeout.
 			// This is a debug log as the only possible error is context timeout.
-			log.WithContextFields(LogFields{"error": err}).Debug(
+			log.WithTraceFields(LogFields{"error": err}).Debug(
 				"acquire SSH handshake semaphore failed")
 				"acquire SSH handshake semaphore failed")
 			return
 			return
 		}
 		}
@@ -1001,7 +1001,7 @@ func (sshServer *sshServer) monitorPortForwardDialError(err error) {
 			opErr.Err == syscall.EMFILE ||
 			opErr.Err == syscall.EMFILE ||
 			opErr.Err == syscall.ENFILE {
 			opErr.Err == syscall.ENFILE {
 
 
-			log.WithContextFields(
+			log.WithTraceFields(
 				LogFields{"error": opErr.Err}).Error(
 				LogFields{"error": opErr.Err}).Error(
 				"port forward dial failed due to unavailable resource")
 				"port forward dial failed due to unavailable resource")
 		}
 		}
@@ -1142,7 +1142,7 @@ func (sshClient *sshClient) run(
 	if err != nil {
 	if err != nil {
 		conn.Close()
 		conn.Close()
 		if !isExpectedTunnelIOError(err) {
 		if !isExpectedTunnelIOError(err) {
-			log.WithContextFields(LogFields{"error": err}).Error("NewActivityMonitoredConn failed")
+			log.WithTraceFields(LogFields{"error": err}).Error("NewActivityMonitoredConn failed")
 		}
 		}
 		return
 		return
 	}
 	}
@@ -1273,7 +1273,7 @@ func (sshClient *sshClient) run(
 		// This is a Debug log due to noise. The handshake often fails due to I/O
 		// This is a Debug log due to noise. The handshake often fails due to I/O
 		// errors as clients frequently interrupt connections in progress when
 		// errors as clients frequently interrupt connections in progress when
 		// client-side load balancing completes a connection to a different server.
 		// client-side load balancing completes a connection to a different server.
-		log.WithContextFields(LogFields{"error": result.err}).Debug("handshake failed")
+		log.WithTraceFields(LogFields{"error": result.err}).Debug("handshake failed")
 		return
 		return
 	}
 	}
 
 
@@ -1292,7 +1292,7 @@ func (sshClient *sshClient) run(
 
 
 	if !sshClient.sshServer.registerEstablishedClient(sshClient) {
 	if !sshClient.sshServer.registerEstablishedClient(sshClient) {
 		conn.Close()
 		conn.Close()
-		log.WithContext().Warning("register failed")
+		log.WithTrace().Warning("register failed")
 		return
 		return
 	}
 	}
 
 
@@ -1450,16 +1450,16 @@ func (sshClient *sshClient) authLogCallback(conn ssh.ConnMetadata, method string
 			now := int64(monotime.Now())
 			now := int64(monotime.Now())
 			if atomic.CompareAndSwapInt64(&sshClient.sshServer.lastAuthLog, int64(lastAuthLog), now) {
 			if atomic.CompareAndSwapInt64(&sshClient.sshServer.lastAuthLog, int64(lastAuthLog), now) {
 				count := atomic.SwapInt64(&sshClient.sshServer.authFailedCount, 0)
 				count := atomic.SwapInt64(&sshClient.sshServer.authFailedCount, 0)
-				log.WithContextFields(
+				log.WithTraceFields(
 					LogFields{"lastError": err, "failedCount": count}).Warning("authentication failures")
 					LogFields{"lastError": err, "failedCount": count}).Warning("authentication failures")
 			}
 			}
 		}
 		}
 
 
-		log.WithContextFields(LogFields{"error": err, "method": method}).Debug("authentication failed")
+		log.WithTraceFields(LogFields{"error": err, "method": method}).Debug("authentication failed")
 
 
 	} else {
 	} else {
 
 
-		log.WithContextFields(LogFields{"error": err, "method": method}).Debug("authentication success")
+		log.WithTraceFields(LogFields{"error": err, "method": method}).Debug("authentication success")
 	}
 	}
 }
 }
 
 
@@ -1601,12 +1601,12 @@ func (sshClient *sshClient) handleSSHRequests(requests <-chan *ssh.Request) {
 		if err == nil {
 		if err == nil {
 			err = request.Reply(true, responsePayload)
 			err = request.Reply(true, responsePayload)
 		} else {
 		} else {
-			log.WithContextFields(LogFields{"error": err}).Warning("request failed")
+			log.WithTraceFields(LogFields{"error": err}).Warning("request failed")
 			err = request.Reply(false, nil)
 			err = request.Reply(false, nil)
 		}
 		}
 		if err != nil {
 		if err != nil {
 			if !isExpectedTunnelIOError(err) {
 			if !isExpectedTunnelIOError(err) {
-				log.WithContextFields(LogFields{"error": err}).Warning("response failed")
+				log.WithTraceFields(LogFields{"error": err}).Warning("response failed")
 			}
 			}
 		}
 		}
 
 
@@ -1818,7 +1818,7 @@ func (sshClient *sshClient) handleNewRandomStreamChannel(
 	channel, requests, err := newChannel.Accept()
 	channel, requests, err := newChannel.Accept()
 	if err != nil {
 	if err != nil {
 		if !isExpectedTunnelIOError(err) {
 		if !isExpectedTunnelIOError(err) {
-			log.WithContextFields(LogFields{"error": err}).Warning("accept new channel failed")
+			log.WithTraceFields(LogFields{"error": err}).Warning("accept new channel failed")
 		}
 		}
 		return
 		return
 	}
 	}
@@ -1836,7 +1836,7 @@ func (sshClient *sshClient) handleNewRandomStreamChannel(
 			received = int(n)
 			received = int(n)
 			if err != nil {
 			if err != nil {
 				if !isExpectedTunnelIOError(err) {
 				if !isExpectedTunnelIOError(err) {
-					log.WithContextFields(LogFields{"error": err}).Warning("receive failed")
+					log.WithTraceFields(LogFields{"error": err}).Warning("receive failed")
 				}
 				}
 				// Fall through and record any bytes received...
 				// Fall through and record any bytes received...
 			}
 			}
@@ -1847,7 +1847,7 @@ func (sshClient *sshClient) handleNewRandomStreamChannel(
 			sent = int(n)
 			sent = int(n)
 			if err != nil {
 			if err != nil {
 				if !isExpectedTunnelIOError(err) {
 				if !isExpectedTunnelIOError(err) {
-					log.WithContextFields(LogFields{"error": err}).Warning("send failed")
+					log.WithTraceFields(LogFields{"error": err}).Warning("send failed")
 				}
 				}
 			}
 			}
 		}
 		}
@@ -1880,7 +1880,7 @@ func (sshClient *sshClient) handleNewPacketTunnelChannel(
 	packetTunnelChannel, requests, err := newChannel.Accept()
 	packetTunnelChannel, requests, err := newChannel.Accept()
 	if err != nil {
 	if err != nil {
 		if !isExpectedTunnelIOError(err) {
 		if !isExpectedTunnelIOError(err) {
-			log.WithContextFields(LogFields{"error": err}).Warning("accept new channel failed")
+			log.WithTraceFields(LogFields{"error": err}).Warning("accept new channel failed")
 		}
 		}
 		return
 		return
 	}
 	}
@@ -1930,7 +1930,7 @@ func (sshClient *sshClient) handleNewPacketTunnelChannel(
 		flowActivityUpdaterMaker,
 		flowActivityUpdaterMaker,
 		metricUpdater)
 		metricUpdater)
 	if err != nil {
 	if err != nil {
-		log.WithContextFields(LogFields{"error": err}).Warning("start packet tunnel client failed")
+		log.WithTraceFields(LogFields{"error": err}).Warning("start packet tunnel client failed")
 		sshClient.setPacketTunnelChannel(nil)
 		sshClient.setPacketTunnelChannel(nil)
 	}
 	}
 }
 }
@@ -2177,7 +2177,7 @@ func (sshClient *sshClient) runOSLSender() {
 				break
 				break
 			}
 			}
 			if !isExpectedTunnelIOError(err) {
 			if !isExpectedTunnelIOError(err) {
-				log.WithContextFields(LogFields{"error": err}).Warning("sendOSLRequest failed")
+				log.WithTraceFields(LogFields{"error": err}).Warning("sendOSLRequest failed")
 			}
 			}
 
 
 			// If the request failed, retry after a delay (with exponential backoff)
 			// If the request failed, retry after a delay (with exponential backoff)
@@ -2243,7 +2243,7 @@ func (sshClient *sshClient) rejectNewChannel(newChannel ssh.NewChannel, logMessa
 	reason := ssh.Prohibited
 	reason := ssh.Prohibited
 
 
 	// Note: Debug level, as logMessage may contain user traffic destination address information
 	// Note: Debug level, as logMessage may contain user traffic destination address information
-	log.WithContextFields(
+	log.WithTraceFields(
 		LogFields{
 		LogFields{
 			"channelType":  newChannel.ChannelType(),
 			"channelType":  newChannel.ChannelType(),
 			"logMessage":   logMessage,
 			"logMessage":   logMessage,
@@ -2300,7 +2300,7 @@ func (sshClient *sshClient) setHandshakeState(
 
 
 		// This sanity check mitigates malicious clients causing excess CPU use.
 		// This sanity check mitigates malicious clients causing excess CPU use.
 		if i >= MAX_AUTHORIZATIONS {
 		if i >= MAX_AUTHORIZATIONS {
-			log.WithContext().Warning("too many authorizations")
+			log.WithTrace().Warning("too many authorizations")
 			break
 			break
 		}
 		}
 
 
@@ -2309,7 +2309,7 @@ func (sshClient *sshClient) setHandshakeState(
 			authorization)
 			authorization)
 
 
 		if err != nil {
 		if err != nil {
-			log.WithContextFields(
+			log.WithTraceFields(
 				LogFields{"error": err}).Warning("verify authorization failed")
 				LogFields{"error": err}).Warning("verify authorization failed")
 			continue
 			continue
 		}
 		}
@@ -2317,7 +2317,7 @@ func (sshClient *sshClient) setHandshakeState(
 		authorizationID := base64.StdEncoding.EncodeToString(verifiedAuthorization.ID)
 		authorizationID := base64.StdEncoding.EncodeToString(verifiedAuthorization.ID)
 
 
 		if common.Contains(authorizedAccessTypes, verifiedAuthorization.AccessType) {
 		if common.Contains(authorizedAccessTypes, verifiedAuthorization.AccessType) {
-			log.WithContextFields(
+			log.WithTraceFields(
 				LogFields{"accessType": verifiedAuthorization.AccessType}).Warning("duplicate authorization access type")
 				LogFields{"accessType": verifiedAuthorization.AccessType}).Warning("duplicate authorization access type")
 			continue
 			continue
 		}
 		}
@@ -2352,7 +2352,7 @@ func (sshClient *sshClient) setHandshakeState(
 		sessionID, ok := sshClient.sshServer.authorizationSessionIDs[authorizationID]
 		sessionID, ok := sshClient.sshServer.authorizationSessionIDs[authorizationID]
 		if ok && sessionID != sshClient.sessionID {
 		if ok && sessionID != sshClient.sessionID {
 
 
-			log.WithContextFields(
+			log.WithTraceFields(
 				LogFields{"authorizationID": authorizationID}).Warning("duplicate active authorization")
 				LogFields{"authorizationID": authorizationID}).Warning("duplicate active authorization")
 
 
 			// Invoke asynchronously to avoid deadlocks.
 			// Invoke asynchronously to avoid deadlocks.
@@ -2644,7 +2644,7 @@ func (sshClient *sshClient) isPortForwardPermitted(
 		}
 		}
 	}
 	}
 
 
-	log.WithContextFields(
+	log.WithTraceFields(
 		LogFields{
 		LogFields{
 			"type": portForwardType,
 			"type": portForwardType,
 			"port": port,
 			"port": port,
@@ -2809,7 +2809,7 @@ func (sshClient *sshClient) establishedPortForward(
 	if !sshClient.allocatePortForward(portForwardType) {
 	if !sshClient.allocatePortForward(portForwardType) {
 
 
 		portForwardLRU.CloseOldest()
 		portForwardLRU.CloseOldest()
-		log.WithContext().Debug("closed LRU port forward")
+		log.WithTrace().Debug("closed LRU port forward")
 
 
 		state.availablePortForwardCond.L.Lock()
 		state.availablePortForwardCond.L.Lock()
 		for !sshClient.allocatePortForward(portForwardType) {
 		for !sshClient.allocatePortForward(portForwardType) {
@@ -2911,7 +2911,7 @@ func (sshClient *sshClient) handleTCPChannel(
 
 
 	dialStartTime := monotime.Now()
 	dialStartTime := monotime.Now()
 
 
-	log.WithContextFields(LogFields{"hostToConnect": hostToConnect}).Debug("resolving")
+	log.WithTraceFields(LogFields{"hostToConnect": hostToConnect}).Debug("resolving")
 
 
 	ctx, cancelCtx := context.WithTimeout(sshClient.runCtx, remainingDialTimeout)
 	ctx, cancelCtx := context.WithTimeout(sshClient.runCtx, remainingDialTimeout)
 	IPs, err := (&net.Resolver{}).LookupIPAddr(ctx, hostToConnect)
 	IPs, err := (&net.Resolver{}).LookupIPAddr(ctx, hostToConnect)
@@ -2966,7 +2966,7 @@ func (sshClient *sshClient) handleTCPChannel(
 
 
 	remoteAddr := net.JoinHostPort(IP.String(), strconv.Itoa(portToConnect))
 	remoteAddr := net.JoinHostPort(IP.String(), strconv.Itoa(portToConnect))
 
 
-	log.WithContextFields(LogFields{"remoteAddr": remoteAddr}).Debug("dialing")
+	log.WithTraceFields(LogFields{"remoteAddr": remoteAddr}).Debug("dialing")
 
 
 	ctx, cancelCtx = context.WithTimeout(sshClient.runCtx, remainingDialTimeout)
 	ctx, cancelCtx = context.WithTimeout(sshClient.runCtx, remainingDialTimeout)
 	fwdConn, err := (&net.Dialer{}).DialContext(ctx, "tcp", remoteAddr)
 	fwdConn, err := (&net.Dialer{}).DialContext(ctx, "tcp", remoteAddr)
@@ -2992,7 +2992,7 @@ func (sshClient *sshClient) handleTCPChannel(
 	fwdChannel, requests, err := newChannel.Accept()
 	fwdChannel, requests, err := newChannel.Accept()
 	if err != nil {
 	if err != nil {
 		if !isExpectedTunnelIOError(err) {
 		if !isExpectedTunnelIOError(err) {
-			log.WithContextFields(LogFields{"error": err}).Warning("accept new channel failed")
+			log.WithTraceFields(LogFields{"error": err}).Warning("accept new channel failed")
 		}
 		}
 		return
 		return
 	}
 	}
@@ -3044,13 +3044,13 @@ func (sshClient *sshClient) handleTCPChannel(
 		updater,
 		updater,
 		lruEntry)
 		lruEntry)
 	if err != nil {
 	if err != nil {
-		log.WithContextFields(LogFields{"error": err}).Error("NewActivityMonitoredConn failed")
+		log.WithTraceFields(LogFields{"error": err}).Error("NewActivityMonitoredConn failed")
 		return
 		return
 	}
 	}
 
 
 	// Relay channel to forwarded connection.
 	// Relay channel to forwarded connection.
 
 
-	log.WithContextFields(LogFields{"remoteAddr": remoteAddr}).Debug("relaying")
+	log.WithTraceFields(LogFields{"remoteAddr": remoteAddr}).Debug("relaying")
 
 
 	// TODO: relay errors to fwdChannel.Stderr()?
 	// TODO: relay errors to fwdChannel.Stderr()?
 	relayWaitGroup := new(sync.WaitGroup)
 	relayWaitGroup := new(sync.WaitGroup)
@@ -3065,7 +3065,7 @@ func (sshClient *sshClient) handleTCPChannel(
 		atomic.AddInt64(&bytesDown, bytes)
 		atomic.AddInt64(&bytesDown, bytes)
 		if err != nil && err != io.EOF {
 		if err != nil && err != io.EOF {
 			// Debug since errors such as "connection reset by peer" occur during normal operation
 			// Debug since errors such as "connection reset by peer" occur during normal operation
-			log.WithContextFields(LogFields{"error": err}).Debug("downstream TCP relay failed")
+			log.WithTraceFields(LogFields{"error": err}).Debug("downstream TCP relay failed")
 		}
 		}
 		// Interrupt upstream io.Copy when downstream is shutting down.
 		// Interrupt upstream io.Copy when downstream is shutting down.
 		// TODO: this is done to quickly cleanup the port forward when
 		// TODO: this is done to quickly cleanup the port forward when
@@ -3077,7 +3077,7 @@ func (sshClient *sshClient) handleTCPChannel(
 		fwdConn, fwdChannel, make([]byte, SSH_TCP_PORT_FORWARD_COPY_BUFFER_SIZE))
 		fwdConn, fwdChannel, make([]byte, SSH_TCP_PORT_FORWARD_COPY_BUFFER_SIZE))
 	atomic.AddInt64(&bytesUp, bytes)
 	atomic.AddInt64(&bytesUp, bytes)
 	if err != nil && err != io.EOF {
 	if err != nil && err != io.EOF {
-		log.WithContextFields(LogFields{"error": err}).Debug("upstream TCP relay failed")
+		log.WithTraceFields(LogFields{"error": err}).Debug("upstream TCP relay failed")
 	}
 	}
 	// Shutdown special case: fwdChannel will be closed and return EOF when
 	// Shutdown special case: fwdChannel will be closed and return EOF when
 	// the SSH connection is closed, but we need to explicitly close fwdConn
 	// the SSH connection is closed, but we need to explicitly close fwdConn
@@ -3087,7 +3087,7 @@ func (sshClient *sshClient) handleTCPChannel(
 
 
 	relayWaitGroup.Wait()
 	relayWaitGroup.Wait()
 
 
-	log.WithContextFields(
+	log.WithTraceFields(
 		LogFields{
 		LogFields{
 			"remoteAddr": remoteAddr,
 			"remoteAddr": remoteAddr,
 			"bytesUp":    atomic.LoadInt64(&bytesUp),
 			"bytesUp":    atomic.LoadInt64(&bytesUp),

+ 11 - 11
psiphon/server/udp.go

@@ -50,7 +50,7 @@ func (sshClient *sshClient) handleUDPChannel(newChannel ssh.NewChannel) {
 	sshChannel, requests, err := newChannel.Accept()
 	sshChannel, requests, err := newChannel.Accept()
 	if err != nil {
 	if err != nil {
 		if !isExpectedTunnelIOError(err) {
 		if !isExpectedTunnelIOError(err) {
-			log.WithContextFields(LogFields{"error": err}).Warning("accept new channel failed")
+			log.WithTraceFields(LogFields{"error": err}).Warning("accept new channel failed")
 		}
 		}
 		return
 		return
 	}
 	}
@@ -97,7 +97,7 @@ func (mux *udpPortForwardMultiplexer) run() {
 		if e := recover(); e != nil {
 		if e := recover(); e != nil {
 			err := errors.Tracef(
 			err := errors.Tracef(
 				"udpPortForwardMultiplexer panic: %s: %s", e, debug.Stack())
 				"udpPortForwardMultiplexer panic: %s: %s", e, debug.Stack())
-			log.WithContextFields(LogFields{"error": err}).Warning("run failed")
+			log.WithTraceFields(LogFields{"error": err}).Warning("run failed")
 		}
 		}
 	}()
 	}()
 
 
@@ -109,7 +109,7 @@ func (mux *udpPortForwardMultiplexer) run() {
 		if err != nil {
 		if err != nil {
 			if err != io.EOF {
 			if err != io.EOF {
 				// Debug since I/O errors occur during normal operation
 				// Debug since I/O errors occur during normal operation
-				log.WithContextFields(LogFields{"error": err}).Debug("readUdpgwMessage failed")
+				log.WithTraceFields(LogFields{"error": err}).Debug("readUdpgwMessage failed")
 			}
 			}
 			break
 			break
 		}
 		}
@@ -134,7 +134,7 @@ func (mux *udpPortForwardMultiplexer) run() {
 			if 0 != bytes.Compare(portForward.remoteIP, message.remoteIP) ||
 			if 0 != bytes.Compare(portForward.remoteIP, message.remoteIP) ||
 				portForward.remotePort != message.remotePort {
 				portForward.remotePort != message.remotePort {
 
 
-				log.WithContext().Warning("UDP port forward remote address mismatch")
+				log.WithTrace().Warning("UDP port forward remote address mismatch")
 				continue
 				continue
 			}
 			}
 
 
@@ -168,7 +168,7 @@ func (mux *udpPortForwardMultiplexer) run() {
 			// Can't defer sshClient.closedPortForward() here;
 			// Can't defer sshClient.closedPortForward() here;
 			// relayDownstream will call sshClient.closedPortForward()
 			// relayDownstream will call sshClient.closedPortForward()
 
 
-			log.WithContextFields(
+			log.WithTraceFields(
 				LogFields{
 				LogFields{
 					"remoteAddr": fmt.Sprintf("%s:%d", dialIP.String(), dialPort),
 					"remoteAddr": fmt.Sprintf("%s:%d", dialIP.String(), dialPort),
 					"connID":     message.connID}).Debug("dialing")
 					"connID":     message.connID}).Debug("dialing")
@@ -182,7 +182,7 @@ func (mux *udpPortForwardMultiplexer) run() {
 				mux.sshClient.sshServer.monitorPortForwardDialError(err)
 				mux.sshClient.sshServer.monitorPortForwardDialError(err)
 
 
 				// Note: Debug level, as logMessage may contain user traffic destination address information
 				// Note: Debug level, as logMessage may contain user traffic destination address information
-				log.WithContextFields(LogFields{"error": err}).Debug("DialUDP failed")
+				log.WithTraceFields(LogFields{"error": err}).Debug("DialUDP failed")
 				continue
 				continue
 			}
 			}
 
 
@@ -211,7 +211,7 @@ func (mux *udpPortForwardMultiplexer) run() {
 			if err != nil {
 			if err != nil {
 				lruEntry.Remove()
 				lruEntry.Remove()
 				mux.sshClient.closedPortForward(portForwardTypeUDP, 0, 0)
 				mux.sshClient.closedPortForward(portForwardTypeUDP, 0, 0)
-				log.WithContextFields(LogFields{"error": err}).Error("NewActivityMonitoredConn failed")
+				log.WithTraceFields(LogFields{"error": err}).Error("NewActivityMonitoredConn failed")
 				continue
 				continue
 			}
 			}
 
 
@@ -238,7 +238,7 @@ func (mux *udpPortForwardMultiplexer) run() {
 		_, err = portForward.conn.Write(message.packet)
 		_, err = portForward.conn.Write(message.packet)
 		if err != nil {
 		if err != nil {
 			// Debug since errors such as "write: operation not permitted" occur during normal operation
 			// Debug since errors such as "write: operation not permitted" occur during normal operation
-			log.WithContextFields(LogFields{"error": err}).Debug("upstream UDP relay failed")
+			log.WithTraceFields(LogFields{"error": err}).Debug("upstream UDP relay failed")
 			// The port forward's goroutine will complete cleanup
 			// The port forward's goroutine will complete cleanup
 			portForward.conn.Close()
 			portForward.conn.Close()
 		}
 		}
@@ -304,7 +304,7 @@ func (portForward *udpPortForward) relayDownstream() {
 		if err != nil {
 		if err != nil {
 			if err != io.EOF {
 			if err != io.EOF {
 				// Debug since errors such as "use of closed network connection" occur during normal operation
 				// Debug since errors such as "use of closed network connection" occur during normal operation
-				log.WithContextFields(LogFields{"error": err}).Debug("downstream UDP relay failed")
+				log.WithTraceFields(LogFields{"error": err}).Debug("downstream UDP relay failed")
 			}
 			}
 			break
 			break
 		}
 		}
@@ -329,7 +329,7 @@ func (portForward *udpPortForward) relayDownstream() {
 		if err != nil {
 		if err != nil {
 			// Close the channel, which will interrupt the main loop.
 			// Close the channel, which will interrupt the main loop.
 			portForward.mux.sshChannel.Close()
 			portForward.mux.sshChannel.Close()
-			log.WithContextFields(LogFields{"error": err}).Debug("downstream UDP relay failed")
+			log.WithTraceFields(LogFields{"error": err}).Debug("downstream UDP relay failed")
 			break
 			break
 		}
 		}
 
 
@@ -348,7 +348,7 @@ func (portForward *udpPortForward) relayDownstream() {
 	bytesDown := atomic.LoadInt64(&portForward.bytesDown)
 	bytesDown := atomic.LoadInt64(&portForward.bytesDown)
 	portForward.mux.sshClient.closedPortForward(portForwardTypeUDP, bytesUp, bytesDown)
 	portForward.mux.sshClient.closedPortForward(portForwardTypeUDP, bytesUp, bytesDown)
 
 
-	log.WithContextFields(
+	log.WithTraceFields(
 		LogFields{
 		LogFields{
 			"remoteAddr": fmt.Sprintf("%s:%d",
 			"remoteAddr": fmt.Sprintf("%s:%d",
 				net.IP(portForward.remoteIP).String(), portForward.remotePort),
 				net.IP(portForward.remoteIP).String(), portForward.remotePort),

+ 7 - 7
psiphon/server/webServer.go

@@ -110,7 +110,7 @@ func RunWebServer(
 		return errors.Trace(err)
 		return errors.Trace(err)
 	}
 	}
 
 
-	log.WithContextFields(
+	log.WithTraceFields(
 		LogFields{"localAddress": localAddress}).Info("starting")
 		LogFields{"localAddress": localAddress}).Info("starting")
 
 
 	err = nil
 	err = nil
@@ -138,7 +138,7 @@ func RunWebServer(
 			}
 			}
 		}
 		}
 
 
-		log.WithContextFields(
+		log.WithTraceFields(
 			LogFields{"localAddress": localAddress}).Info("stopped")
 			LogFields{"localAddress": localAddress}).Info("stopped")
 	}()
 	}()
 
 
@@ -151,7 +151,7 @@ func RunWebServer(
 
 
 	waitGroup.Wait()
 	waitGroup.Wait()
 
 
-	log.WithContextFields(
+	log.WithTraceFields(
 		LogFields{"localAddress": localAddress}).Info("exiting")
 		LogFields{"localAddress": localAddress}).Info("exiting")
 
 
 	return err
 	return err
@@ -247,7 +247,7 @@ func (webServer *webServer) handshakeHandler(w http.ResponseWriter, r *http.Requ
 	}
 	}
 
 
 	if err != nil {
 	if err != nil {
-		log.WithContextFields(LogFields{"error": err}).Warning("failed")
+		log.WithTraceFields(LogFields{"error": err}).Warning("failed")
 		w.WriteHeader(http.StatusNotFound)
 		w.WriteHeader(http.StatusNotFound)
 		return
 		return
 	}
 	}
@@ -278,7 +278,7 @@ func (webServer *webServer) connectedHandler(w http.ResponseWriter, r *http.Requ
 	}
 	}
 
 
 	if err != nil {
 	if err != nil {
-		log.WithContextFields(LogFields{"error": err}).Warning("failed")
+		log.WithTraceFields(LogFields{"error": err}).Warning("failed")
 		w.WriteHeader(http.StatusNotFound)
 		w.WriteHeader(http.StatusNotFound)
 		return
 		return
 	}
 	}
@@ -303,7 +303,7 @@ func (webServer *webServer) statusHandler(w http.ResponseWriter, r *http.Request
 	}
 	}
 
 
 	if err != nil {
 	if err != nil {
-		log.WithContextFields(LogFields{"error": err}).Warning("failed")
+		log.WithTraceFields(LogFields{"error": err}).Warning("failed")
 		w.WriteHeader(http.StatusNotFound)
 		w.WriteHeader(http.StatusNotFound)
 		return
 		return
 	}
 	}
@@ -329,7 +329,7 @@ func (webServer *webServer) clientVerificationHandler(w http.ResponseWriter, r *
 	}
 	}
 
 
 	if err != nil {
 	if err != nil {
-		log.WithContextFields(LogFields{"error": err}).Warning("failed")
+		log.WithTraceFields(LogFields{"error": err}).Warning("failed")
 		w.WriteHeader(http.StatusNotFound)
 		w.WriteHeader(http.StatusNotFound)
 		return
 		return
 	}
 	}