1
0

Improve logging

This commit is contained in:
2024-01-07 11:07:20 +01:00
parent aec90ead0c
commit f1472a95e9

View File

@@ -1,31 +1,31 @@
console.loggerName = 'js.timer'; const log = Java.type('org.slf4j.LoggerFactory').getLogger('js.utils.timer');
console.log('Load timer module'); log.info('Load utils.timer');
class Timer { class Timer {
#timers = new Object(); #timers = new Object();
constructor() { constructor() {
console.log('Initialization of timer helper class'); log.info('Initialization of timer helper class');
} }
create(identifier, timeout, func) { create(identifier, timeout, func) {
console.debug(`Create timer with identifier ${identifier}`); log.debug(`Create timer with identifier ${identifier}`);
this.#timers[identifier] = actions.ScriptExecution.createTimer(identifier, timeout, func); this.#timers[identifier] = actions.ScriptExecution.createTimer(identifier, timeout, func);
} }
cancel(identifier) { cancel(identifier) {
// Return if no timer with the respactive identifier is available // Return if no timer with the respactive identifier is available
if (!this.#timers.hasOwnProperty(identifier)) { if (!this.#timers.hasOwnProperty(identifier)) {
console.debug(`No timer with identifier ${identifier} available to cancel`); log.debug(`No timer with identifier ${identifier} available to cancel`);
return false; return false;
} }
// Check if timer is active // Check if timer is active
if (!this.#timers[identifier].isActive()) { if (!this.#timers[identifier].isActive()) {
console.debug(`Timer with identifier ${identifier} not running. Cancel anyway`); log.debug(`Timer with identifier ${identifier} not running. Cancel anyway`);
} else { } else {
console.debug(`Cancel timer with identifier ${identifier}`); log.debug(`Cancel timer with identifier ${identifier}`);
} }
// Cancel timer // Cancel timer
@@ -43,7 +43,7 @@ class Timer {
// Return if no timers available // Return if no timers available
if (timers.length == 0) { if (timers.length == 0) {
console.debug('No timers available to cancel'); log.debug('No timers available to cancel');
return false; return false;
} }