Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Server-Side Components/Script Includes/Log Utils/Code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var log_utils = Class.create();
log_utils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
initialize: function(debug, noDebugMethods) {
this.debug = false; // Flag to allow debug or not on this script include
this.noDebugMethods = []; // Array of methods to not log from

if (debug) {
this.debug = debug;
}

if (noDebugMethods) {
this.noDebugMethods = noDebugMethods.split(',');
}

// Global Variables For Use In Script

},

/**
* Description: Takes in a method name and message and logs the message in gs.info if debug and method isn't in noDebugMethods
* Parameters: [string] - methodName: name of method calling log.
[string] - msg: message being called in log.
* Returns: None.
*/

log: function(methodName, msg) {
if (this.debug && this.noDebugMethods.indexOf(methodName) === -1) {
gs.debug('[Log Utils - ' + methodName + '] ' + msg);
}
},

56 changes: 56 additions & 0 deletions Server-Side Components/Script Includes/Log Utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
This is a lightweight utility for managing logging within Script Includes.
It provides a simple, configurable way to enable or disable debug logs during development and to exclude specific methods from logging when necessary.

This approach helps maintain clean logs, reduces noise during debugging, and allows for quick toggling of logging behavior once development is complete.

Usage:
You can call the log method anywhere inside your Script Include to record a log message:
this.log(<method_name>, <message>);

Example:
this.log('processData', 'Starting data processing...');

Initialization Parameters:
Logging behavior is controlled through the parameters passed to the initialize method when creating the Script Include instance.

var utils = new scope.utils(true, 'methodName1,methodName2');

Parameters:
======================================================================================================================
|debug | Boolean false | Enables or disables logging. Set to true to allow logs, false to suppress them. |
|noDebugMethods | String "" | A comma-separated list of method names that should not produce logs. |
======================================================================================================================

Example Use Case:
If you’re developing a new method that depends on existing, stable methods, you can temporarily disable logging for the known-good methods.
For example:

var utils = new scope.utils(true, 'validatedMethod');

This enables logs for all methods except validatedMethod, keeping your system logs focused on what you’re currently debugging.

When development is complete, you can remove the parameters (or set debug to false) to disable all logs.

Notes:
The script uses gs.debug() for logging to keep logs easily filterable within the system logs.
You can switch to gs.info(), gs.warn(), or gs.error() depending on your needs.

Logging should typically remain disabled (debug = false) in production to avoid unnecessary system overhead.

This utility is flexible and can be dropped into almost any Script Include with minimal setup.

Example in Context:

var example_utils = Class.create();
example_utils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
initialize: function(debug, noDebugMethods) {
this.logger = new log_utils(debug, noDebugMethods);
},

processData: function() {
this.logger.log('processData', 'Starting process...');
// ...your logic here...
this.logger.log('processData', 'Process completed successfully.');
}
});

Loading