UNPKG

smartfacecloud-emulator-dispatcher

Version:

Handles Emulator Dispatcher Part of SmartfaceCloud

45 lines (39 loc) 1.21 kB
const send = require("../http/logging/log").send; /** * If both parameters are not provided, logging is disabled * @param {boolean} Whether logging is enabled or not * @param {string} Which service to be used (LogToConsole.SERVICES), could be undefined */ function LogToConsole(enabled, service) { var self = this; this.enabled = (typeof enabled == 'undefined') ? false : enabled; this.service = (typeof service == 'undefined') ? '' : service; if (ALLOWED_SERVICES.indexOf(this.service) < 0) { this.service = ''; } this.log = function() { arguments = Array.prototype.slice.call(arguments); self.service && arguments.unshift(self.service); if (self.enabled) { console.log.apply(this, arguments); send("all", "dispatcher", arguments.join(" ")); } }; } const SERVICES = { CONTROL: '[CONTROL]', FILE_TRANSFER: '[FILE]', DEBUGGER: '[DEBUGGER]', UI: '[UI]', HTTP: '[HTTP]', PROCESS: '[PROCESS]' }; const ALLOWED_SERVICES = [ SERVICES.CONTROL, SERVICES.FILE_TRANSFER, SERVICES.DEBUGGER, SERVICES.UI, SERVICES.HTTP, SERVICES.PROCESS ]; module.exports = LogToConsole;