|
| 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