Skip to content

Commit f1d1a1e

Browse files
authored
Added a Log Utils to the Script Includes Directory
1 parent 3a56f60 commit f1d1a1e

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var log_utils = Class.create();
2+
log_utils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
3+
initialize: function(debug, noDebugMethods) {
4+
this.debug = false; // Flag to allow debug or not on this script include
5+
this.noDebugMethods = []; // Array of methods to not log from
6+
7+
if (debug) {
8+
this.debug = debug;
9+
}
10+
11+
if (noDebugMethods) {
12+
this.noDebugMethods = noDebugMethods.split(',');
13+
}
14+
15+
// Global Variables For Use In Script
16+
17+
},
18+
19+
/**
20+
* Description: Takes in a method name and message and logs the message in gs.info if debug and method isn't in noDebugMethods
21+
* Parameters: [string] - methodName: name of method calling log.
22+
[string] - msg: message being called in log.
23+
* Returns: None.
24+
*/
25+
26+
log: function(methodName, msg) {
27+
if (this.debug && this.noDebugMethods.indexOf(methodName) === -1) {
28+
gs.debug('[Log Utils - ' + methodName + '] ' + msg);
29+
}
30+
},
31+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
This is a lightweight utility for managing logging within Script Includes.
2+
It provides a simple, configurable way to enable or disable debug logs during development and to exclude specific methods from logging when necessary.
3+
4+
This approach helps maintain clean logs, reduces noise during debugging, and allows for quick toggling of logging behavior once development is complete.
5+
6+
Usage:
7+
You can call the log method anywhere inside your Script Include to record a log message:
8+
this.log(<method_name>, <message>);
9+
10+
Example:
11+
this.log('processData', 'Starting data processing...');
12+
13+
Initialization Parameters:
14+
Logging behavior is controlled through the parameters passed to the initialize method when creating the Script Include instance.
15+
16+
var utils = new scope.utils(true, 'methodName1,methodName2');
17+
18+
Parameters:
19+
======================================================================================================================
20+
|debug | Boolean false | Enables or disables logging. Set to true to allow logs, false to suppress them. |
21+
|noDebugMethods | String "" | A comma-separated list of method names that should not produce logs. |
22+
======================================================================================================================
23+
24+
Example Use Case:
25+
If you’re developing a new method that depends on existing, stable methods, you can temporarily disable logging for the known-good methods.
26+
For example:
27+
28+
var utils = new scope.utils(true, 'validatedMethod');
29+
30+
This enables logs for all methods except validatedMethod, keeping your system logs focused on what you’re currently debugging.
31+
32+
When development is complete, you can remove the parameters (or set debug to false) to disable all logs.
33+
34+
Notes:
35+
The script uses gs.debug() for logging to keep logs easily filterable within the system logs.
36+
You can switch to gs.info(), gs.warn(), or gs.error() depending on your needs.
37+
38+
Logging should typically remain disabled (debug = false) in production to avoid unnecessary system overhead.
39+
40+
This utility is flexible and can be dropped into almost any Script Include with minimal setup.
41+
42+
Example in Context:
43+
44+
var example_utils = Class.create();
45+
example_utils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
46+
initialize: function(debug, noDebugMethods) {
47+
this.logger = new log_utils(debug, noDebugMethods);
48+
},
49+
50+
processData: function() {
51+
this.logger.log('processData', 'Starting process...');
52+
// ...your logic here...
53+
this.logger.log('processData', 'Process completed successfully.');
54+
}
55+
});
56+

0 commit comments

Comments
 (0)