Logging line number of Script Includes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2019 06:56 AM
Is it possible to log the line number of a script includes for debugging?
I have a very long Script Includes called during an import transform map. It would be very helpful for debugging to identify some of the specific lines processed. I added several gs.log entries into the Script Includes but it is cumbersome to accurately maintain the gs.log("line number X") when adding lines to or removing lines from the Script Includes. Is there a dynamic function that can more dynamically record the Script Includes line?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2019 07:03 AM
I like to use a variable to store my log then post it as a single entry.
var logStr = " --- Transform Log --- \n\n";
logStr += "Line 1 finished \n";
logStr += "Line 2 errored \n";
gs.log(logStr);
This will show up in 1 entry in your logs. It helps to keep everything organized. Just make sure you use \n at the end of the string so it prints a new line.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2019 07:26 AM
I do not believe there is a function to return the Script Include line number. Here are some techniques I have found to be helpful for debugging large script includes.
- Split the Script Include into lots of small functions. If you do this, then you will no longer be concerned about line number: Instead you will be concerned about the name of the function.
- During initialization, add: "this.debug = true;"
- Prefix each gs.log statement with "if (this.debug) gs.log(...". Now you can easily turn debugging on or off.
- The first parameter of gs.log should begin with the name of the function (or method) from where it is being called.
- Set the second parameter (source) of gs.log to this.type. Now in sys_log you can easily filter all messages which came from this script include. Another option is to set the source to this.type + "." + functionname.
Now your debug statements look like this
if (this.debug) gs.log("functionname arg1=" + arg1 + " arg2=" + arg2, this.type);
You may be working with a legacy script include, in which case it is not viable to split up the script include into a lot of small functions. That's okay. Instead of functionname use some other literal (e.g. section name) which will tell you from where the log statement was called.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2019 08:12 PM
Sorry for the delay. At first it appeared that "this.debug = true;" with if (this.debug) gs.log(... worked, except that an error appeared about 1,000 down in the script includes that there were too many errors to check.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2019 07:35 AM
It depends on the browser you are using.
You can use lineNumber for Mozilla compatible browsers such as FireFox, Chrome, MS Edge and Opera.
But it doesn't work for MS IE.
Here are some other properties that you can use in catch block.
Hope it helps,
Regards,
Yusuf