Skip to content

Commit 13e5705

Browse files
authored
Create LoggerUtility.js
1 parent 8155a28 commit 13e5705

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//UI Script
2+
(function() {
3+
'use strict';
4+
5+
window.Logger = (function() {
6+
const isDebugEnabled = true; // change it to 'true' for production when needed
7+
8+
function formatMessage(level, ...args) {
9+
const timestamp = new Date().toISOString();
10+
return [`[${timestamp}] [${level}]`, ...args];
11+
}
12+
13+
return {
14+
info: (...args) => isDebugEnabled && console.info(...formatMessage('INFO', ...args)),
15+
debug: (...args) => isDebugEnabled && console.debug(...formatMessage('DEBUG', ...args)),
16+
warn: (...args) => isDebugEnabled && console.warn(...formatMessage('WARN', ...args)),
17+
error: (...args) => console.error(...formatMessage('ERROR', ...args)) // always log errors
18+
};
19+
})();
20+
})();
21+
22+
23+
Client Side Usage:
24+
25+
* Logger.info('Form loaded successfully');
26+
* Logger.debug('Field value:', g_form.getValue('short_description'));
27+
* Logger.warn('Potential issue detected');
28+
* Logger.error('An error occurred', errorObject);

0 commit comments

Comments
 (0)