diff --git a/Server-Side Components/Script Includes/Developer Debug Utility/DeveloperDebugUtility.js b/Server-Side Components/Script Includes/Developer Debug Utility/DeveloperDebugUtility.js new file mode 100644 index 0000000000..b2c1ef6eb7 --- /dev/null +++ b/Server-Side Components/Script Includes/Developer Debug Utility/DeveloperDebugUtility.js @@ -0,0 +1,35 @@ +var DeveloperDebugUtility = Class.create(); +DeveloperDebugUtility.prototype = { + initialize: function() {}, + + // Checks if debug logging is enabled via system property + + _enable_debug: function() { + // System Property: enable_debug_for_scripts (true/false) + return gs.getProperty('enable_debug_for_scripts') == 'true'; + }, + + // Controlled debug logger + // {String} message - The message to log + _debug: function(message) { + if (this._enable_debug()) { + gs.info('[DEBUG LOG] ' + message); + } + }, + + // Example function where controlled debugging can be used + addFunction: function(data) { + try { + // Example logic: simulate some operation + this._debug('Executing addFunction with data: ' + JSON.stringify(data)); + + // core logic here + + this._debug('addFunction executed successfully.'); + } catch (e) { + this._debug('Error executing addFunction:\n' + e); + } + }, + + type: 'DeveloperDebugUtility' +}; diff --git a/Server-Side Components/Script Includes/Developer Debug Utility/README.md b/Server-Side Components/Script Includes/Developer Debug Utility/README.md new file mode 100644 index 0000000000..e9a6473e88 --- /dev/null +++ b/Server-Side Components/Script Includes/Developer Debug Utility/README.md @@ -0,0 +1,16 @@ +# Developer Debug Utility (Controlled Logging) +Create a systemProperty - enable_debug_for_scripts (Boolean value) + +# Overview +This utility provides a centralized, configurable debug logging mechanism for developers. +Instead of using gs.info(), gs.log(), or gs.warn() - which create permanent logs in the system, developers can now log messages conditionally through a system property. + +When the property 'enable_debug_for_scripts' is set to 'true', debug messages are logged; otherwise, all debug calls are ignored. +This makes it ideal for debugging issues in Production without modifying code or flooding system logs. + + +# Objective +To provide a reusable, lightweight debugging utility that allows developers to: +- Enable/disable debug logs globally via a system property. +- Avoid unnecessary system log entries when debugging is not needed. +- Maintain clean, controlled, and consistent debug output across server-side scripts.