Skip to content

Commit 41877af

Browse files
Developer Debug Utility (Controlled Logging) (#2513)
* Create DeveloperDebugUtility.js * Create README.md * Update README.md
1 parent 324359b commit 41877af

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var DeveloperDebugUtility = Class.create();
2+
DeveloperDebugUtility.prototype = {
3+
initialize: function() {},
4+
5+
// Checks if debug logging is enabled via system property
6+
7+
_enable_debug: function() {
8+
// System Property: enable_debug_for_scripts (true/false)
9+
return gs.getProperty('enable_debug_for_scripts') == 'true';
10+
},
11+
12+
// Controlled debug logger
13+
// {String} message - The message to log
14+
_debug: function(message) {
15+
if (this._enable_debug()) {
16+
gs.info('[DEBUG LOG] ' + message);
17+
}
18+
},
19+
20+
// Example function where controlled debugging can be used
21+
addFunction: function(data) {
22+
try {
23+
// Example logic: simulate some operation
24+
this._debug('Executing addFunction with data: ' + JSON.stringify(data));
25+
26+
// core logic here
27+
28+
this._debug('addFunction executed successfully.');
29+
} catch (e) {
30+
this._debug('Error executing addFunction:\n' + e);
31+
}
32+
},
33+
34+
type: 'DeveloperDebugUtility'
35+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Developer Debug Utility (Controlled Logging)
2+
Create a systemProperty - enable_debug_for_scripts (Boolean value)
3+
4+
# Overview
5+
This utility provides a centralized, configurable debug logging mechanism for developers.
6+
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.
7+
8+
When the property 'enable_debug_for_scripts' is set to 'true', debug messages are logged; otherwise, all debug calls are ignored.
9+
This makes it ideal for debugging issues in Production without modifying code or flooding system logs.
10+
11+
12+
# Objective
13+
To provide a reusable, lightweight debugging utility that allows developers to:
14+
- Enable/disable debug logs globally via a system property.
15+
- Avoid unnecessary system log entries when debugging is not needed.
16+
- Maintain clean, controlled, and consistent debug output across server-side scripts.

0 commit comments

Comments
 (0)