add logging

This commit is contained in:
jane 2021-05-27 14:26:12 -04:00
parent 8f6adec59e
commit 8dbf96a3a2
1 changed files with 8 additions and 1 deletions

View File

@ -1,5 +1,10 @@
import * as net from 'net';
import { functions } from './lights.js'
import Logger, { levels } from './logger.js';
const cfg = JSON.parse(fs.readFileSync('./config.json'));
const log = new Logger("server", cfg.log_level ? levels[cfg.log_level] : levels.INFO);
const hostname = '0.0.0.0';
const port = 29999;
@ -10,7 +15,9 @@ export function recv(callback, errorCallback) {
server.on('connection', (con) => {
console.log('connection recieved: ' +
con.remoteAddress + ":" + con.remotePort);
con.write(JSON.stringify(Object.keys(functions)));
let functions_str = JSON.stringify(Object.keys(functions));
con.write(functions_str);
log.debug(`sending ${functions_str}`);
con.on('data', (data) => {
callback(data);
});