homebridge-tsvesync
Version:
Homebridge plugin for VeSync devices including Levoit air purifiers, humidifiers, and Etekcity smart outlets
69 lines • 2.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginLogger = exports.LogLevel = void 0;
var LogLevel;
(function (LogLevel) {
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
LogLevel[LogLevel["INFO"] = 1] = "INFO";
LogLevel[LogLevel["WARN"] = 2] = "WARN";
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
LogLevel[LogLevel["NONE"] = 4] = "NONE";
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
class PluginLogger {
constructor(log, debugMode = false) {
this.log = log;
this.debugMode = debugMode;
this.currentLevel = debugMode ? LogLevel.DEBUG : LogLevel.INFO;
}
setLevel(level) {
this.currentLevel = level;
}
getLevel() {
return this.currentLevel;
}
debug(message, ...args) {
if (this.currentLevel <= LogLevel.DEBUG) {
this.log.info(message, ...args);
}
}
info(message, ...args) {
if (this.currentLevel <= LogLevel.INFO) {
this.log.info(message, ...args);
}
}
warn(message, ...args) {
if (this.currentLevel <= LogLevel.WARN) {
this.log.warn(message, ...args);
}
}
error(message, ...args) {
if (this.currentLevel <= LogLevel.ERROR) {
this.log.error(message, ...args);
}
}
operationStart(context) {
if (this.currentLevel <= LogLevel.DEBUG) {
const { deviceName, deviceType, operation } = context;
this.debug(`[${deviceName}] Starting ${operation}`, { deviceType });
}
}
operationEnd(context, error) {
if (this.currentLevel <= LogLevel.DEBUG) {
const { deviceName, deviceType, operation } = context;
if (error) {
this.debug(`[${deviceName}] Failed ${operation}:`, error, { deviceType });
}
else {
this.debug(`[${deviceName}] Completed ${operation}`, { deviceType });
}
}
}
stateChange(context) {
if (this.currentLevel <= LogLevel.DEBUG) {
const { deviceName, characteristic, value } = context;
this.debug(`[${deviceName}] ${characteristic} changed to ${value}`);
}
}
}
exports.PluginLogger = PluginLogger;
//# sourceMappingURL=logger.js.map