Skip to content

Commit ae52ab5

Browse files
A Fix Script has been added to detect the log statements such as gs.log, gs.debug etc. in production environment which is against the best practices. The Fix script 'Scan for log statements' returns the line numbers where such statements have been used. The script is scalable and can be used to scan any table, or add any statement type in future.
1 parent bd56627 commit ae52ab5

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
BgiovevC1ze9ekbSNu313pR_3YPr9xUl8hAleZQ_Rnfiowfr5T_DAmii6h_xnZewjTA5kJDPZ8x14S0gIPG4eStZ_r0uGIAEaMA2i5ojlbIKORDDapgOMutOHKJaSSwf5uZ0VkEcLzooGIDWB0v16daIWWmH_U_tcnLaTE7bj5lyq4EtAk53xdL2hPu7eGFz949_eZIJg4np37S0xRegM9y_dmXRrQ8sLopLNT_af4u_BCPeNIg9Gwq5Wjn9Qj-xbi8bazd-3t7Koe2HKHH2vqOryT-dhuZufc9zUI_l55ev-4cGovoOeBX2wc13EwKh1HIMaW9kwiWljZ-0An9_loh6WU6FYCcnEV9xS2xDXUbHOoWeuOdg76lvyor5qfEN3jOQ46xXIoW5vidkXaoBVtMSLMcBFbrFBZuJWI0Zq4lZU6TiRvzbveuo1rDeAv126QIJhGCuE0SDcvzuV96dbttSOQ-ZgAUumexHi91tJ_97V2MDP9q5Ms-5Y0Mg9r0PNqCibJqaPEnkxgYPIYePZZZdYPYWbOtM4eTteRkWZxAXO_lRTEq7Bon9z0cpiIRBaZLIg7LiMeLZk8F2gHservOdv1_Y1D_rFznoMifC65doHeUJMmIqw6u6vCAM7C9B8YpsXDLWfL6sPrSqTQwVK1WHG_lmjTI_4U6Qb1fAgFg
1+
rJLf1AAbFV5OE_dPDo2VP8-l8MV3ExKZUxo9R7aB416ndfQD0tQ1_cF14Qj4Ok9A9LvkHmb6rlQDxvq_CHedxSDw7EhbBUDTsNooyiRl4IOCw1tH2TTAqmIJn14tRyDgKyznlboIqhJu1RSqd_c95cB7wqcQpE-Qu1q1rMFrp6wxJlpujSDe6RoRuuLINet8T893EjjT00zLbpWFSoio-gPtWGYuCZ9r-SrJllBTNIv1XR22kMPzJeDtNo47GzEs4c7KZwU911yqSpzjgvOcAMfrPShDKvxaUeqidyNwSS9KXR8BB1jdvJaLkQxxDxJQPPP9CbTHQiTKyvr6TNJMriHPOtidllo_b5eExLLyqfLV3Jfwm5nzPJEPgs5O25my5uZuJvGH4AK5xlcTYRujDlX41YLevqwQJrzvFxMr6gufeB-KSzcw4B1flvJiXmGAQzZGcYgFm0fKsipTcukW0NaR8wtrQbgsWPSyMk0614LTwpNXDahR8rxD6dK1kewISM02sBux3wFbR5z8X46LImaHV7_kvCdni-8JDd-pfIdjicv5HVObrfbPKi0LiveZs7RQLbxDQgan_qIz-YmbfPEGq_Qhx24auoceP7yy9RGQ3fBaUVsoDpLStjbJblbjl1UiPzdaWkRsSqoxPbD5p_kQ7mB6-TOILSPI8oujpLw
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?><record_update table="sys_script_fix">
2+
<sys_script_fix action="INSERT_OR_UPDATE">
3+
<before>false</before>
4+
<description>This utility script helps in finding the various log statements which are against the bad practices such as gs.log,gs.info,console.log etc should bot be used in production environment. The script returns the line numbers where such statements are used which can help identify such statements.</description>
5+
<name>Scan for log statements</name>
6+
<record_for_rollback>true</record_for_rollback>
7+
<script><![CDATA[var tableName = 'sys_script';
8+
var sysId = '3b59c70d47441210788164f2e16d4386';
9+
var gr = new GlideRecord(tableName);
10+
gr.addQuery('sys_id',sysId);
11+
gr.query();
12+
var script = "";
13+
if(gr.next()){
14+
script = gr.getValue('script');
15+
}
16+
17+
var logStatements = ['gs.log', 'gs.info', 'gs.debug', 'console.log', 'gs.print'];
18+
19+
// Split the script into lines
20+
var lines = script.split("\n");
21+
22+
// Array to store line numbers where log statements are found
23+
var logLineNumbers = [];
24+
25+
// Iterate over each line and check for log statements
26+
for (var i = 0; i < lines.length; i++) {
27+
var line = lines[i];
28+
// Check if the line contains any of the log statements
29+
for (var j = 0; j < logStatements.length; j++) {
30+
if (line.includes(logStatements[j])) {
31+
logLineNumbers.push(i + 1); // Line numbers are 1-based, so we add 1
32+
break; // No need to check further for this line
33+
}
34+
}
35+
}
36+
37+
// Output the line numbers with log statements
38+
gs.print('Log statements found at line numbers: ' + logLineNumbers.join(', '));
39+
]]></script>
40+
<sys_class_name>sys_script_fix</sys_class_name>
41+
<sys_created_by>admin</sys_created_by>
42+
<sys_created_on>2024-10-21 13:49:57</sys_created_on>
43+
<sys_id>5c5dd84747d95210788164f2e16d43b8</sys_id>
44+
<sys_mod_count>0</sys_mod_count>
45+
<sys_name>Scan for log statements</sys_name>
46+
<sys_package display_value="Example Instance Checks" source="x_appe_exa_checks">ca8467c41b9abc10ce0f62c3b24bcbaa</sys_package>
47+
<sys_policy/>
48+
<sys_scope display_value="Example Instance Checks">ca8467c41b9abc10ce0f62c3b24bcbaa</sys_scope>
49+
<sys_update_name>sys_script_fix_5c5dd84747d95210788164f2e16d43b8</sys_update_name>
50+
<sys_updated_by>admin</sys_updated_by>
51+
<sys_updated_on>2024-10-21 13:49:57</sys_updated_on>
52+
<unloadable>false</unloadable>
53+
</sys_script_fix>
54+
<sys_es_latest_script action="INSERT_OR_UPDATE">
55+
<id>5c5dd84747d95210788164f2e16d43b8</id>
56+
<sys_created_by>admin</sys_created_by>
57+
<sys_created_on>2024-10-21 13:49:56</sys_created_on>
58+
<sys_id>3cfd1c4747d95210788164f2e16d434f</sys_id>
59+
<sys_mod_count>0</sys_mod_count>
60+
<sys_updated_by>admin</sys_updated_by>
61+
<sys_updated_on>2024-10-21 13:49:56</sys_updated_on>
62+
<table>sys_script_fix</table>
63+
<use_es_latest>true</use_es_latest>
64+
</sys_es_latest_script>
65+
</record_update>

0 commit comments

Comments
 (0)