| 1 |
/** |
| 2 |
* Optimole Logger Module |
| 3 |
* Provides centralized logging functionality with debug mode support |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* Create utility logger with simplified structure |
| 8 |
*/ |
| 9 |
export const optmlLogger = { |
| 10 |
/** |
| 11 |
* Check if debug mode is enabled |
| 12 |
* @returns {boolean} True if debug mode is active |
| 13 |
*/ |
| 14 |
isDebug: function() { |
| 15 |
return new URLSearchParams(location.search).has('optml_debug') || |
| 16 |
localStorage.getItem('optml_debug') !== null; |
| 17 |
}, |
| 18 |
|
| 19 |
/** |
| 20 |
* Generic log method |
| 21 |
* @param {string} level - Log level (info, warn, error) |
| 22 |
* @param {...any} args - Arguments to log |
| 23 |
*/ |
| 24 |
log: function(level, ...args) { |
| 25 |
if (this.isDebug()) { |
| 26 |
console[level]('[Optimole]', ...args); |
| 27 |
} |
| 28 |
}, |
| 29 |
|
| 30 |
/** |
| 31 |
* Log info messages |
| 32 |
* @param {...any} args - Arguments to log |
| 33 |
*/ |
| 34 |
info: function(...args) { |
| 35 |
this.log('info', ...args); |
| 36 |
}, |
| 37 |
|
| 38 |
/** |
| 39 |
* Log warning messages |
| 40 |
* @param {...any} args - Arguments to log |
| 41 |
*/ |
| 42 |
warn: function(...args) { |
| 43 |
this.log('warn', ...args); |
| 44 |
}, |
| 45 |
|
| 46 |
/** |
| 47 |
* Log error messages |
| 48 |
* @param {...any} args - Arguments to log |
| 49 |
*/ |
| 50 |
error: function(...args) { |
| 51 |
this.log('error', ...args); |
| 52 |
}, |
| 53 |
|
| 54 |
/** |
| 55 |
* Log table data |
| 56 |
* @param {Object|Array} data - Data to display in table format |
| 57 |
*/ |
| 58 |
table: function(data) { |
| 59 |
if (this.isDebug()) { |
| 60 |
console.log('[Optimole] Table:'); |
| 61 |
console.table(data); |
| 62 |
} |
| 63 |
} |
| 64 |
}; |
| 65 |
|