UNPKG

homebridge-smartsystem

Version:

SmartServer (Proxy Websockets to TCP sockets, Smappee MQTT, Duotecno IP Nodes, Homekit interface)

43 lines (36 loc) 1.28 kB
///////////// // Logging // ///////////// // add LogLevels per type at runtime export enum LogLevel { noLog = 0, log = 1, debug = 2 }; export const logSettings = { "*": LogLevel.log, "master": LogLevel.log, "protocol": LogLevel.noLog, "webapp": LogLevel.log, "p1": LogLevel.log, "shelly": LogLevel.log, "power": LogLevel.log, "smartapp": LogLevel.log }; // can be overriden with server log function export let logFunction = console.log; export function setLogFunction(F) { console.log(">>>>>>>>> NOT changing logfunction to: " + F.name + " <<<<<<<<<<"); // logFunction = (m) => { F(m) }; } export function err(type: string, message: string | object) { logFunction(type + ": " + ((typeof message === "string") ? message : JSON.stringify(message))); } export function log(type: string, message: string | object) { const level = logSettings[type] ?? logSettings["*"]; if (level) { logFunction(type + ": " + ((typeof message === "string") ? message : JSON.stringify(message))); } } export function debug(type: string, message: string | object) { const level = logSettings[type] ?? logSettings["*"]; if (level === LogLevel.debug) { logFunction(type + "> " + ((typeof message === "string") ? message : JSON.stringify(message))); } }