File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Server-Side Components/Script Includes/NonProdLogUtils Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ var LoggingUtils = Class . create ( ) ;
2+ LoggingUtils . prototype = {
3+ initialize : function ( ) {
4+ } ,
5+
6+ /**
7+ * @param {string } message The message to log.
8+ * @param {string } [type='info'] The type of log. Options: 'info', 'warn', 'error'.
9+ * @returns {void }
10+ *
11+ * This utility function logs a message only if the current instance is non-production.
12+ * Use it in other server-side scripts like this:
13+ * var logUtil = new LoggingUtils();
14+ * logUtil.log('This message will only show in dev and test environments.');
15+ */
16+ log : function ( message , type ) {
17+ // Get the current instance name from a system property
18+ var instanceName = gs . getProperty ( 'instance_name' ) ;
19+
20+ // You must define your production instance name.
21+ // For example, if your production instance is 'mycompanyprod'.
22+ var productionInstanceName = 'mycompanyprod' ;
23+
24+ // Check if the current instance name is NOT the production instance name
25+ if ( instanceName && instanceName != productionInstanceName ) {
26+ type = type || 'info' ;
27+
28+ // Determine the correct logging function based on the specified type
29+ switch ( type ) {
30+ case 'warn' :
31+ gs . warn ( message ) ;
32+ break ;
33+ case 'error' :
34+ gs . error ( message ) ;
35+ break ;
36+ default :
37+ gs . log ( message ) ;
38+ break ;
39+ }
40+ }
41+ } ,
42+
43+ type : 'LoggingUtils'
44+ } ;
You can’t perform that action at this time.
0 commit comments