[Libreoffice-commits] online.git: loleaflet/html loleaflet/src loolwsd.xml.in wsd/FileServer.cpp wsd/LOOLWSD.cpp

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Fri Nov 15 18:02:07 UTC 2019


 loleaflet/html/loleaflet.html.m4 |    2 ++
 loleaflet/src/core/Socket.js     |   26 +++++++++++++++++---------
 loolwsd.xml.in                   |    1 +
 wsd/FileServer.cpp               |    8 +++++++-
 wsd/LOOLWSD.cpp                  |    1 +
 5 files changed, 28 insertions(+), 10 deletions(-)

New commits:
commit 98617e40e2bc9ec5c0c1b5637099d74c5aab4515
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Nov 15 18:01:02 2019 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Nov 15 18:01:02 2019 +0000

    Enable protocol debugging by default in debug mode.
    
    Also add a config option for logging.protocol - to help catch early
    protocol issues during startup.
    
    Change-Id: I6f0cc6dcf14b2797bc6b2bd36c44750d74eb0608

diff --git a/loleaflet/html/loleaflet.html.m4 b/loleaflet/html/loleaflet.html.m4
index 7af24cdf1..6fc5afbfa 100644
--- a/loleaflet/html/loleaflet.html.m4
+++ b/loleaflet/html/loleaflet.html.m4
@@ -224,6 +224,7 @@ ifelse(MOBILEAPP,[true],
       window.outOfFocusTimeoutSecs = 1000000;
       window.idleTimeoutSecs = 1000000;
       window.reuseCookies = '';
+      window.protocolDebug = false;
       window.tileSize = 256;],
      [window.host = '%HOST%';
       window.serviceRoot = '%SERVICE_ROOT%';
@@ -234,6 +235,7 @@ ifelse(MOBILEAPP,[true],
       window.outOfFocusTimeoutSecs = %OUT_OF_FOCUS_TIMEOUT_SECS%;
       window.idleTimeoutSecs = %IDLE_TIMEOUT_SECS%;
       window.reuseCookies = '%REUSE_COOKIES%';
+      window.protocolDebug = %PROTOCOL_DEBUG%;
       window.tileSize = 256;])
 syscmd([cat ]GLOBAL_JS)dnl
     </script>
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 6512dd92d..f391e4108 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -140,9 +140,7 @@ L.Socket = L.Class.extend({
 			// Only attempt to log text frames, not binary ones.
 			if (typeof msg === 'string') {
 				L.Log.log(msg, L.OUTGOING, coords);
-				if (this._map._docLayer && this._map._docLayer._debug) {
-					console.log2(+new Date() + ' %cOUTGOING%c: ' + msg.concat(' ').replace(' ', '%c '), 'background:#fbb;color:black', 'color:red', 'color:black');
-				}
+				this._logSocket('OUTGOING', msg);
 			}
 		}
 		else {
@@ -155,9 +153,7 @@ L.Socket = L.Class.extend({
 		// Only attempt to log text frames, not binary ones.
 		if (typeof msg === 'string') {
 			L.Log.log(msg, L.OUTGOING, coords);
-			if (this._map._docLayer && this._map._docLayer._debug) {
-				console.log2(+new Date() + ' %cOUTGOING%c: ' + msg.concat(' ').replace(' ', '%c '), 'background:#fbb;color:black', 'color:red', 'color:black');
-			}
+			this._logSocket('OUTGOING', msg);
 		}
 
 		this.socket.send(msg);
@@ -237,6 +233,20 @@ L.Socket = L.Class.extend({
 		return true;
 	},
 
+	_logSocket: function(type, msg) {
+
+		var fullDebug = this._map._docLayer && this._map._docLayer._debug;
+		if (!window.protocolDebug && !fullDebug)
+			return;
+
+		if (!fullDebug && msg.length > 256) // for reasonable performance.
+			msg = msg.substring(0,256) + '<truncated ' + (msg.length - 256) + 'chars>';
+
+		var color = type === 'OUTGOING' ? 'color:red' : 'color:blue';
+		console.log2(+new Date() + ' %c' + type + '%c: ' + msg.concat(' ').replace(' ', '%c '),
+			     'background:#ddf;color:black', color, 'color:black');
+	},
+
 	_onMessage: function (e) {
 		var imgBytes, index, textMsg, img;
 
@@ -254,9 +264,7 @@ L.Socket = L.Class.extend({
 			textMsg = String.fromCharCode.apply(null, imgBytes.subarray(0, index));
 		}
 
-		if (this._map._docLayer && this._map._docLayer._debug) {
-			console.log2(+new Date() + ' %cINCOMING%c: ' + textMsg.concat(' ').replace(' ', '%c '), 'background:#ddf;color:black', 'color:blue', 'color:black');
-		}
+		this._logSocket('INCOMING', textMsg);
 
 		var command = this.parseServerCmd(textMsg);
 		if (textMsg.startsWith('loolserver ')) {
diff --git a/loolwsd.xml.in b/loolwsd.xml.in
index 83c35b9ce..79a930d7f 100644
--- a/loolwsd.xml.in
+++ b/loolwsd.xml.in
@@ -41,6 +41,7 @@
     <logging>
         <color type="bool">true</color>
         <level type="string" desc="Can be 0-8, or none (turns off logging), fatal, critical, error, warning, notice, information, debug, trace" default="@LOOLWSD_LOGLEVEL@">@LOOLWSD_LOGLEVEL@</level>
+	<protocol type="bool" descr="Enable minimal client-site JS protocol logging from the start">@ENABLE_DEBUG@</protocol>
         <file enable="@LOOLWSD_LOG_TO_FILE@">
             <property name="path" desc="Log file path.">@LOOLWSD_LOGFILE@</property>
             <property name="rotation" desc="Log file rotation strategy. See Poco FileChannel.">never</property>
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 32373f3b0..5f49450c1 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -633,6 +633,8 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
         }
     }
 
+    const auto& config = Application::instance().config();
+
     Poco::replaceInPlace(preprocess, std::string("%ACCESS_TOKEN%"), escapedAccessToken);
     Poco::replaceInPlace(preprocess, std::string("%ACCESS_TOKEN_TTL%"), std::to_string(tokenTtl));
     Poco::replaceInPlace(preprocess, std::string("%ACCESS_HEADER%"), escapedAccessHeader);
@@ -640,13 +642,17 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
     Poco::replaceInPlace(preprocess, std::string("%VERSION%"), std::string(LOOLWSD_VERSION_HASH));
     Poco::replaceInPlace(preprocess, std::string("%SERVICE_ROOT%"), LOOLWSD::ServiceRoot);
 
+    std::string protocolDebug = "false";
+    if (config.getBool("logging.protocol"))
+        protocolDebug = "true";
+    Poco::replaceInPlace(preprocess, std::string("%PROTOCOL_DEBUG%"), protocolDebug);
+
     static const std::string linkCSS("<link rel=\"stylesheet\" href=\"%s/loleaflet/" LOOLWSD_VERSION_HASH "/%s.css\">");
     static const std::string scriptJS("<script src=\"%s/loleaflet/" LOOLWSD_VERSION_HASH "/%s.js\"></script>");
 
     std::string brandCSS(Poco::format(linkCSS, LOOLWSD::ServiceRoot, std::string(BRANDING)));
     std::string brandJS(Poco::format(scriptJS, LOOLWSD::ServiceRoot, std::string(BRANDING)));
 
-    const auto& config = Application::instance().config();
 #if ENABLE_SUPPORT_KEY
     const std::string keyString = config.getString("support_key", "");
     SupportKey key(keyString);
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 6672ec6d2..5a0bc7f60 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -797,6 +797,7 @@ void LOOLWSD::initialize(Application& self)
             { "child_root_path", "jails" },
             { "file_server_root_path", "loleaflet/.." },
             { "lo_jail_subpath", "lo" },
+            { "logging.protocol", "false" },
             { "logging.anonymize.filenames", "false" }, // Deprecated.
             { "logging.anonymize.usernames", "false" }, // Deprecated.
             // { "logging.anonymize.anonymize_user_data", "false" }, // Do not set to fallback on filename/username.


More information about the Libreoffice-commits mailing list