- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 11-25-2020 03:47 PM
I am thinking of suggesting GSLog as a Standard at our company. (Logging is out-of-control here)
What do you think? Any thoughts or advice on these recommendations below?
1. Summary
This page includes:
- Discussion about Syslog logging issues
- Recommendation on how to use GSLog to solve these issues.
- Use of the Script Debugger for Server Side Scripts
- Recommendations for debugging Ajax Script Includes (Client Callable).
2. Contents
- Summary
- Contents
- Debugging
- SysLog Problems
- Solution
- GSLog
- Example Usage
3. Debugging
3.1. Debugging Server Side Scripts
The SN Script Debugger tool within SN works well for debugging. This this Tech Short Video on the Script Debugger.
3.2. Debugging Script Includes that use Ajax
Debugging Glide Ajax Scripts poses additional issues.
- The Script Debugger does not support Client Callable Script Includes - i.e. script includes that inherit global.AbstractAjaxProcessor.
If someone Knows how to use the Script Debugger for AJAX, then please let me know!!
3.2.1. Two Recommendations
- Stubs. Make all your Client Callable Script Includes just stubs - that call a standard script include. So develop your Ajax Script Includes in pairs. Put 90% of your code in the Standard Script Include (not Client callable) so that the logging can be done and you can use ATF Tests.
- Call Parent Constructor. Within your Client Callable Script, create a prototype.initialize() function and include code to create the GSlog instance. See example below. Using this approach, you can include GSLog in your Client Callable Script Incudes. This is not as effective as using the Script Debugger - but it works. You have to use the old fashioned way of debugging (i.e. logs). Please let me know - if you discover a better approach!!!! Also I have not yet tested this yet (except as generic inheritance). See example Script below. Let me if there are issues.
3.3. Debugging Client Side Java
- CTTL SHIFT ALT J. Press CTRL SHIFT ALT J when in the Browser on a SN Page. This opens a mini Window into which you can cut and paste client Side Java Code. I have not used this much (I only just found this).
- CTRL SHIFT I. When in Google, press CTRL SHIFT I. This will bring up the Tools and the Console. Put Console.log() statements in your client side Java code. This is standard Advice.
- Other Methods. I am sure there are hundreds of other methods for debugging Client Side Java. Let me know your favourite!
4. SysLog Problems
The logging in the System Log (syslog) is out of control in our SN systems.
4.1. Impact
This has two impacts:
- Performance.
- It makes it harder to perform debugging.
4.2. Evidence
- Logging Rate. If you filter the SysLog in SN DEV using this filter (see below), you find about 2,500 log entries per minute, which is about 41 per second! This must be impacting performance!
- Total Log Entries. The syslog table has millions of rows. I can;t even count them. I tried to count them using getRowCount() but it locked up the system! This makes it quite hard to perform debugging. It is time consuming to form queries to find the log entries that you want.
4.3. Root Cause of Logging Issues
There are several root causes:
- There is no Company Standard for logging.
- Developers are not switching off debugging before new features go into production.
- Developers are not using the GSLog script include (see below).
- Developers are not bothering to fix run time errors - even when there are errors in the syslog.
- Testers are not testing to ensure logging is switched off.
5. Solution
I would suggest the following solution as Best Practice:
- Always Use GSLog (see below).
- Turn off you debugging after you have finished debugging using a system Property (see GSLog documentation below).
- In the System log, search for the prefix of your Message which is one of the parameters on the GSlog methods (see below).
- Always look for entries in the System Log At or After a specified Date/Time. otherwise it takes too long to list.
6. GSLog
ServiceNow has a Standard Script include that Simplifies logging and allows logging to be switched on and off using a System Property.
I think we should be using this as a standard going forward. I have tested GSLog and it works great!
7. Example Usage
Below is an example of how to use GSLog in two scenarios:
- In the initialize constructor of a parent class (see the third line).
- In a free bit of code. (look at the bottom).
7.1. Sample Code
var ParentClass = Class.create();
ParentClass.prototype = {
gl: new GSLog("ANZ.TechStore.ScriptIncludeCSDANZExt.debug", "ParentClass"),
initialize: function() { this.gl.logDebug("ParentClass.prototype.initialize"); },
doParent: function() { this.gl.logDebug("Function ParentClass.prototype.doChild"); },
getName: function() { this.gl.logDebug("Function ParentClass.prototype.getName"); }
};
var ChildClass = Class.create();
ChildClass.prototype = Object.extendsObject(ParentClass, {
initialize: function() { ParentClass.prototype.initialize(); this.gl.logDebug("ChildClass.prototype.initialize"); },
doChild: function() { this.gl.logDebug("Function ChildClass.prototype.doChild"); },
getName: function() { this.gl.logDebug("Function ChildClass.prototype.getName"); }
});
var debug = true;
var a = new ChildClass(debug);
a.doChild();
a.doParent();
a.getName();
// valid log levels are all in lower case: debug, info, notice, warning, err, crit
var log = new GSLog("ANZ.TechStore.ScriptIncludeCSDANZExt.debug", "Test");
log.logDebug("Hello");
7.2. Sample Output
Output from the script above.
*** Script [ParentClass]: [DEBUG] ParentClass.prototype.initialize
*** Script [ParentClass]: [DEBUG] ChildClass.prototype.initialize
*** Script [ParentClass]: [DEBUG] Function ChildClass.prototype.doChild
*** Script [ParentClass]: [DEBUG] Function ParentClass.prototype.doChild
*** Script [ParentClass]: [DEBUG] Function ChildClass.prototype.getName
*** Script [Test]: [DEBUG] Hello
7.3. System Property - Naming Convention
Create A System Property to hold your log level using the following naming standard:
<Company Name>.<Application>.<script>.<script>.debug
For example:
ANZ.TechStore.ScriptInclude.CSDANXExt.debug
7.4. Log Levels
Log Levels in the System Property are strings and should be in lower case - such as:
debug, info, notice, warning, err, crit
- 5,625 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@dougconnell , thank you much for this article.
I do have a question though, I see your logging sample output is something executed from a background script. Does this log output show up on syslog ?. I am having difficulty in having this different loglevel entries shown on syslog.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes. The logs will be in syslog. Logs are really hard to find in syslog due to the size of the file and the volume of logging.. However there are two things that make it easier:
- Add a filter that shows logs after a specific date and time and make the time only 5 monutes before when you expected the log message.
- Add a filter based on source as described above for GSlog.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Yes. The logs will be in syslog. Logs are really hard to find in syslog due to the size of the file and the volume of logging.. However there are two things that make it easier:
Add a filter that shows logs after a specific date and time and make the time only 5 monutes before when you expected the log message. - Add a filter based on source as described above for GSlog.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@dougconnell I have my filter setup on syslog based on the scope of the application . When I run my scripts on background, i see log entries on the background script output , but can you please help me with this issue I have created . I am unable to see the logDebug on my syslog, i see all gs.info entries but this one doesn't show up on my syslog.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you for taking the time to post these considerations about logging. I've been building my own enhanced logging library and this was insightful! It gave me the idea to add an optional production block feature for those who want to add such insurance to their scripts while testing stuff out in development. Thanks again for this post, great work! Kudos!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
I replied to Ram117 is another post ...
https://www.servicenow.com/community/developer-forum/gslog/m-p/2464106/highlight/true#M962111
... a bit late to the party on these threads but I was revisiting logging again.
I've been using GSLog for years . As my other reply mentions, millisecond timestamping is available, and the log methods can be wrapped so that the log level is not constantly queried for even if logging is "turned off". Therefore strengthening GSLog use in production environments.
Regards,
Courtenay