refactor(utils): replace console logging with SLF4J logger in TimerMgr

This commit is contained in:
Christian Weimann
2025-01-10 05:48:23 +01:00
parent 18baf76eec
commit 4114f0a4a4

View File

@@ -1,32 +1,31 @@
// Logging // Logging
console.loggerName = "org.openhab.js.utils.TimerMgr"; const log = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.js.utils.TimerMgr');
console.log("Loading utils.TimerMgr");
class TimerMgr { class TimerMgr {
#timers = new Object(); #timers = new Object();
constructor() { constructor() {
console.info('Initialization of TimerMgr helper class'); log.info('Initialization of TimerMgr helper class');
} }
create(id, timeout, func) { create(id, timeout, func) {
console.log("Create timer with id " + id); log.debug("Create timer with id " + id);
this.#timers[id] = actions.ScriptExecution.createTimer(id, timeout, func); this.#timers[id] = actions.ScriptExecution.createTimer(id, 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.log(`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.log(`Timer with identifier ${identifier} not running. Cancel anyway`); log.debug(`Timer with identifier ${identifier} not running. Cancel anyway`);
} else { } else {
console.log(`Cancel timer with identifier ${identifier}`); log.debug(`Cancel timer with identifier ${identifier}`);
} }
// Cancel timer // Cancel timer
@@ -48,7 +47,7 @@ class TimerMgr {
// Return if no timers available // Return if no timers available
if (timers.length == 0) { if (timers.length == 0) {
console.log('No timers available to cancel'); log.debug('No timers available to cancel');
return false; return false;
} }