671f8e4fac56f9dcd5497c1e45e7cda89d98cceb
chmalee
  Wed Apr 19 14:45:03 2023 -0700
Adding an asynchronous logging function for the javascript

diff --git src/hg/js/utils.js src/hg/js/utils.js
index ff669b0..54fc07c 100644
--- src/hg/js/utils.js
+++ src/hg/js/utils.js
@@ -1,21 +1,22 @@
 // Utility JavaScript
 
 // "use strict";
 
 // Don't complain about line break before '||' etc:
 /* jshint -W014 */
+/* jshint esnext: true */
 
 var debug = false;
 
 /* Support these formats for range specifiers.  Note the ()'s around chrom,
  * start and end portions for substring retrieval: */
 var canonicalRangeExp = /^[\s]*([\w._#-]+)[\s]*:[\s]*([-0-9,]+)[\s]*[-_][\s]*([0-9,]+)[\s]*$/;
 var gbrowserRangeExp =  /^[\s]*([\w._#-]+)[\s]*:[\s]*([0-9,]+)[\s]*\.\.[\s]*([0-9,]+)[\s]*$/;
 var lengthRangeExp =    /^[\s]*([\w._#-]+)[\s]*:[\s]*([0-9,]+)[\s]*\+[\s]*([0-9,]+)[\s]*$/;
 var bedRangeExp =       /^[\s]*([\w._#-]+)[\s]+([0-9,]+)[\s]+([0-9,]+)[\s]*$/;
 var sqlRangeExp =       /^[\s]*([\w._#-]+)[\s]*\|[\s]*([0-9,]+)[\s]*\|[\s]*([0-9,]+)[\s]*$/;
 var singleBaseExp =     /^[\s]*([\w._#-]+)[\s]*:[\s]*([0-9,]+)[\s]*$/;
 
 function copyToClipboard(ev) {
     /* copy a piece of text to clipboard. event.target is some DIV or SVG that is an icon. 
      * The attribute data-target of this element is the ID of the element that contains the text to copy. 
@@ -3693,15 +3694,38 @@
                             this.onclick = posting.mapClk;
                         });
     }
 };
 
 function trackHubSkipHubName(name) {
     // Just like hg/lib/trackHub.c's...
     var matches;
     if (name && (matches = name.match(/^hub_[0-9]+_(.*)/)) !== null) {
         return matches[1];
     } else {
         return name;
     }
 }
 
+function parseUrl(url) {
+    // turn a url into some of it's components like server, query-string, etc
+    let protocol, serverName, pathInfo, queryString;
+    let temp;
+    temp = url.split("?");
+    if (temp.length > 1)
+        queryString = temp.slice(1).join("?");
+    temp = temp[0].split("/");
+    protocol = temp[0]; // "https:"
+    serverName = temp[2]; // "genome-test.gi.ucsc.edu"
+    pathInfo = temp.slice(3).join("/"); // "cgi-bin/hgTracks"
+    return {protocol: protocol, serverName: serverName, pathInfo: pathInfo, queryString: queryString};
+}
+
+function writeToApacheLog(msg) {
+    // send msg to web servers error_log
+    // first need to figure out what server and CGI we are requesting:
+    let currUrl = parseUrl(window.location.href);
+    logUrl = currUrl.protocol + "//" + currUrl.serverName + "/" + currUrl.pathInfo + "?_dumpToLog=" + msg;
+    let xmlhttp = new XMLHttpRequest();
+    xmlhttp.open("GET", logUrl, true);
+    xmlhttp.send();  // sends request and exits this function
+}