try { fs.writeFileSync(args.logfile, 'timestamp,src_ip,question_type,question,answer\n') log.info(c.gray('[*]') + ` logging CSV data to ${args.logfile}`) } catch (err) { log.error(c.red('[!]') + ` error writing to --logfile ${args.logfile}:`) const answer = c.cyan(ans.address.padEnd(15)) const address = c.magenta(src.padEnd(21)) log.info(c.blue('[+]') + ` ${time} ${address} A ${answer} ${ans.name}`) } else { log.info(c.blue('[+]') + ` A ${c.cyan(ans.address.padEnd(15))} ${ans.name}`) log.info(c.gray('[*]') + ` server listening on port ${args.port}`) })
connect(){ if(this.mqtt != null) { this.log.info("[BaseClient:connect] Reconnecting to " + this.config.getMqttHost() + " as " + this.config.getClientId()); this.mqtt.reconnect(); return; this.log.info("[BaseClient:connect] Connecting to " + this.config.getMqttHost() + " as " + this.config.getClientId()); this.log.info("[BaseClient:onConnect] MQTT client is connected."); this.emit('connect'); this.log.info("[BaseClient:onOffline] Client has lost connection " + connectionLostCount + " times during the last 5 minutes, reconnect delay adjusted to " + reconnectPeriod + " ms"); this.mqtt.options.reconnectPeriod = reconnectPeriod; this.log.info("[BaseClient:onReconnect] MQTT client is reconnecting."); this.log.info("[BaseClient:onClose] MQTT client connection was closed."); this.emit('close'); }); this.log.info("[BaseClient:onOffline] MQTT client connection is offline. [" + newId + "]"); this.emit('offline'); this.log.info("[BaseClient:onOffline] Connection losses in the last 5 minutes: " + connectionLostCount); this.log.error("[BaseClient:onError] One or more configuration parameters are wrong. Modify the configuration before trying to reconnect."); this.mqtt.end(false, () => { this.log.info("[BaseClient:onError] Closed the MQTT connection due to client misconfiguration"); });