// wsiClientLog.js
// Working Systems, Cooperative
// Nicholas Powers
// 2021-10-28
//
// Send log entry from the client browser to the LaborPower backend.
//
//   Paameters: 
//		logType : valid values 'Error', 'Debug', 'Info', 'Transaction', 'Trace', 'Status' 
//      source  : typically this will be the web page sending the log but it can be anything the makes sense for the log
//      message : the log message to place in the log file.  There is no specific maximum length, but it must fit 
//                into a url so it is not unlimited. This code will truncate to 2000 characters
//
//   Example    : clientLog('Trace', '/jobrequests', `app.computed.pendingCount = ${this.pendingRequests.length}`);
//
//   Will write the following to the log:
//
//		09:39:09.216 **  CLIENT **
//		09:39:09.216 [ USER AGENT] Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36
//		09:39:09.216 [ USER NAME ] PARELECTRICAL
//		09:39:09.216 [    SID    ] 0551DDC50D3253E001A85C1AE0AF526BC
//		09:39:09.216 [   TRACE   ] /jobrequests : app.computed.pendingCount = 6
//

function clientLog(logType, source, message) {
  const img = new Image();   // HACK: setting the source of this new Image will initiate an HTTP GET.  This is a sneaky simple way
							 //       to send the URL without needing to do any Ajax/Axios/Fetch coding
  const url =  "./clientlog?logtype=" + logType + "&source=" + encodeURIComponent(source) + "&message=" + encodeURIComponent(message);
  console.log(`clientLog: ${url}`);
  img.src = url.substring(0, 2000);             // the img goes out of scope after this line and will be garbage collected
}
