Changeset

10587:863aa36a9dd8

net.server_epoll: Add option for reducing debug logging Sometimes all these things just drown out the logs you are interested in with low-level socket noise. Enabled since it's still new and experimental.
author Kim Alvefur <zash@zash.se>
date Sun, 12 Jan 2020 20:35:04 +0100
parents 10586:f86ed818a7f8
children 10588:ceadf3d3fecf
files net/server_epoll.lua
diffstat 1 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/net/server_epoll.lua	Sun Jan 05 02:29:31 2020 +0100
+++ b/net/server_epoll.lua	Sun Jan 12 20:35:04 2020 +0100
@@ -66,6 +66,10 @@
 	max_wait = 86400;
 	min_wait = 1e-06;
 
+	-- Enable extra noisy debug logging
+	-- TODO disable once considered stable
+	verbose = true;
+
 	-- EXPERIMENTAL
 	-- Whether to kill connections in case of callback errors.
 	fatal_errors = false;
@@ -155,6 +159,13 @@
 	self.log("debug", msg, ...);
 end
 
+interface.noise = interface.debug;
+function interface:noise(msg, ...) --luacheck: ignore 212/self
+	if cfg.verbose then
+		return self:debug(msg, ...);
+	end
+end
+
 function interface:error(msg, ...) --luacheck: ignore 212/self
 	self.log("error", msg, ...);
 end
@@ -174,7 +185,7 @@
 	end
 	local listener = self.listeners["on"..what];
 	if not listener then
-		-- self:debug("Missing listener 'on%s'", what); -- uncomment for development and debugging
+		self:noise("Missing listener 'on%s'", what); -- uncomment for development and debugging
 		return;
 	end
 	local ok, err = xpcall(listener, traceback, self, ...);
@@ -262,7 +273,7 @@
 	else
 		self._readtimeout = addtimer(t, function ()
 			if self:on("readtimeout") then
-				self:debug("Read timeout handled");
+				self:noise("Read timeout handled");
 				return cfg.read_timeout;
 			else
 				self:debug("Read timeout not handled, disconnecting");
@@ -287,7 +298,7 @@
 		self._writetimeout:reschedule(t);
 	else
 		self._writetimeout = addtimer(t, function ()
-			self:debug("Write timeout");
+			self:noise("Write timeout");
 			self:on("disconnect", "write timeout");
 			self:destroy();
 		end);
@@ -312,7 +323,7 @@
 	end
 	self._wantread, self._wantwrite = r, w;
 	fds[fd] = self;
-	self:debug("Registered in poller");
+	self:noise("Registered in poller");
 	return true;
 end
 
@@ -347,7 +358,7 @@
 	end
 	self._wantread, self._wantwrite = nil, nil;
 	fds[fd] = nil;
-	self:debug("Unregistered from poller");
+	self:noise("Unregistered from poller");
 	return true;
 end
 
@@ -562,15 +573,15 @@
 		self:setwritetimeout();
 		self:set(true, true);
 	elseif err == "wantread" then
-		self:debug("TLS handshake to wait until readable");
+		self:noise("TLS handshake to wait until readable");
 		self:set(true, false);
 		self:setreadtimeout(cfg.ssl_handshake_timeout);
 	elseif err == "wantwrite" then
-		self:debug("TLS handshake to wait until writable");
+		self:noise("TLS handshake to wait until writable");
 		self:set(false, true);
 		self:setwritetimeout(cfg.ssl_handshake_timeout);
 	else
-		self:debug("TLS handshake error: %s", err);
+		self:error("TLS handshake error: %s", err);
 		self:on("disconnect", err);
 		self:destroy();
 	end
@@ -641,18 +652,18 @@
 end
 
 function interface:pause()
-	self:debug("Pause reading");
+	self:noise("Pause reading");
 	return self:set(false);
 end
 
 function interface:resume()
-	self:debug("Resume reading");
+	self:noise("Resume reading");
 	return self:set(true);
 end
 
 -- Pause connection for some time
 function interface:pausefor(t)
-	self:debug("Pause for %fs", t);
+	self:noise("Pause for %fs", t);
 	if self._pausefor then
 		self._pausefor:close();
 	end
@@ -661,7 +672,7 @@
 	self._pausefor = addtimer(t, function ()
 		self._pausefor = nil;
 		self:set(true);
-		self:debug("Resuming after pause, connection is %s", not self.conn and "missing" or self.conn:dirty() and "dirty" or "clean");
+		self:noise("Resuming after pause, connection is %s", not self.conn and "missing" or self.conn:dirty() and "dirty" or "clean");
 		if self.conn and self.conn:dirty() then
 			self:onreadable();
 		end
@@ -680,7 +691,7 @@
 	if self._write_lock then
 		return
 	end
-	self:debug("Pause writes");
+	self:noise("Pause writes");
 	self._write_lock = true;
 	self:setwritetimeout(false);
 	self:set(nil, false);
@@ -690,7 +701,7 @@
 	if not self._write_lock then
 		return
 	end
-	self:debug("Resume writes");
+	self:noise("Resume writes");
 	self._write_lock = nil;
 	if self.writebuffer[1] then
 		self:setwritetimeout();