diff --git a/UI Pages/Real time log watcher/README.md b/UI Pages/Real time log watcher/README.md new file mode 100644 index 0000000000..2d70d83b3b --- /dev/null +++ b/UI Pages/Real time log watcher/README.md @@ -0,0 +1,5 @@ +This code-snippet will give a new experience how you see logs while debugging. This UI Page can be navigated by https://.service-now.com/log_watcher.do and will give an real time log capture which will help to make debugging easy for developers. You can also search with the keyword to find your desired log. + +The below GIF is a short demo for reference. + +![Log Watcher](https://github.com/abhrajyotikanrar/code-snippets/assets/25823899/ec51bfd2-ec48-40a4-9ae7-8b9fc37fbd56) diff --git a/UI Pages/Real time log watcher/TestScriptInclude.js b/UI Pages/Real time log watcher/TestScriptInclude.js new file mode 100644 index 0000000000..2a1a485123 --- /dev/null +++ b/UI Pages/Real time log watcher/TestScriptInclude.js @@ -0,0 +1,33 @@ +var TestScriptInclude = Class.create(); +TestScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, { + + getLogs: function() { + var query = this.getParameter("sysparm_query"); + var initialFetch = this.getParameter("sysparm_initialFetch"); + var startTime = this.getParameter("sysparm_startTime"); + var response = []; + if (initialFetch == "true") { + startTime = new GlideDateTime().getDisplayValue().toString(); + } + var date = startTime.split(" ")[0]; + var time = startTime.split(" ")[1]; + var grLog = new GlideRecord("syslog"); + grLog.addEncodedQuery(query); + grLog.addEncodedQuery("sys_created_on>=javascript:gs.dateGenerate('" + date.split("-").reverse().join("-") + "','" + time + "')"); + grLog.orderByDesc("sys_created_on"); + grLog.query(); + while (grLog.next()) { + response.push({ + "message": grLog.message.toString(), + "sys_created_on": grLog.sys_created_on.getDisplayValue() + }); + } + + return JSON.stringify({ + "startTime": startTime, + "response": response + }); + }, + + type: 'TestScriptInclude' +}); \ No newline at end of file diff --git a/UI Pages/Real time log watcher/log_watcher.js b/UI Pages/Real time log watcher/log_watcher.js new file mode 100644 index 0000000000..a7293cd2c6 --- /dev/null +++ b/UI Pages/Real time log watcher/log_watcher.js @@ -0,0 +1,54 @@ +******HTML***** + + + + + + +
+
+ +
+ +
+
+
+ +
+ +
+**************** + +**Client Script** +function startLogs() { + setInterval(function() { + var queryText = $j("#filterText").val(); + var query = "messageSTARTSWITH" + queryText; + getLogs(query); + }, 1000); +} + +function getLogs(query) { + var initialFetch = $j("#initialFetch").val(); + var startTime = $j("#startTime").val(); + + var ga = new GlideAjax("TestScriptInclude"); + ga.addParam("sysparm_name", "getLogs"); + ga.addParam("sysparm_initialFetch", initialFetch); + ga.addParam("sysparm_startTime", startTime); + ga.addParam("sysparm_query", query); + ga.getXMLAnswer(function(response) { + var answer = JSON.parse(response); + + gel('initialFetch').value = "false"; + gel('startTime').value = answer.startTime; + + var data = answer.response; + $j("#log_container").empty(); + data.forEach(function(item) { + var elm = "
" + item.sys_created_on + ": " + item.message + "
"; + $j("#log_container").append(elm); + }); + + }); +} \ No newline at end of file