refactor(utils): replace console logging with SLF4J logger in TimerMgr
This commit is contained in:
@@ -1,32 +1,31 @@
|
||||
// Logging
|
||||
console.loggerName = "org.openhab.js.utils.TimerMgr";
|
||||
console.log("Loading utils.TimerMgr");
|
||||
const log = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.js.utils.TimerMgr');
|
||||
|
||||
class TimerMgr {
|
||||
|
||||
#timers = new Object();
|
||||
|
||||
constructor() {
|
||||
console.info('Initialization of TimerMgr helper class');
|
||||
log.info('Initialization of TimerMgr helper class');
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
cancel(identifier) {
|
||||
// Return if no timer with the respactive identifier is available
|
||||
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;
|
||||
}
|
||||
|
||||
// Check if timer is active
|
||||
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 {
|
||||
console.log(`Cancel timer with identifier ${identifier}`);
|
||||
log.debug(`Cancel timer with identifier ${identifier}`);
|
||||
}
|
||||
|
||||
// Cancel timer
|
||||
@@ -48,7 +47,7 @@ class TimerMgr {
|
||||
|
||||
// Return if no timers available
|
||||
if (timers.length == 0) {
|
||||
console.log('No timers available to cancel');
|
||||
log.debug('No timers available to cancel');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user