UNPKG

node-hue-api

Version:
38 lines (37 loc) 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DiscoveryLogger = void 0; const DEBUG = /node-hue-discovery/.test(process.env['NODE_DEBUG'] || ''); class DiscoveryLogger { constructor(name) { this.name = name; } static install(name, browser) { if (DiscoveryLogger.isDebug()) { const logger = new DiscoveryLogger(name); logger.log(`Installing discovery logger`); browser.on('up', (val) => { logger.log(`**up: ${JSON.stringify(val)}`); }); browser.on('down', (val) => { logger.log(`**down: ${JSON.stringify(val)}`); }); browser.on('error', (val) => { logger.log(`**error: ${JSON.stringify(val)}`); }); } } static isDebug() { return DEBUG; } log(event, payload) { if (DiscoveryLogger.isDebug()) { let detail = `${event}`; if (payload) { detail += `\n${JSON.stringify(payload)}`; } console.log(`DiscoveryLogger [${this.name}] :: ${detail}`); } } } exports.DiscoveryLogger = DiscoveryLogger;