From 6e228df0fca9a66dcc4ba1124d5e1ee8a42420dd Mon Sep 17 00:00:00 2001 From: Ondrej Zara Date: Fri, 12 Apr 2019 13:46:27 +0200 Subject: [PATCH] logging --- commands.js | 5 +---- index.js | 9 +++++---- log.js | 8 ++++++++ 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 log.js diff --git a/commands.js b/commands.js index e15fbe6..e5e386b 100644 --- a/commands.js +++ b/commands.js @@ -1,8 +1,5 @@ const EventEmitter = require("events"); - -function log(...args) { - console.log(Date.now(), ...args); -} +const log = require("./log.js").log; class Command extends EventEmitter { constructor(mpd) { diff --git a/index.js b/index.js index 194dc4d..e8cf34a 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,7 @@ #!/usr/bin/env node const commands = require("./commands"); - -function log(...args) { - console.log(Date.now(), ...args); -} +const log = require("./log.js").log; function initConnection(request) { let ws = request.accept(); @@ -62,6 +59,10 @@ function initConnection(request) { waitForCommand(commands.welcome(mpd)); } +exports.logging = function(enabled) { + log.enabled = enabled; +} + exports.ws2mpd = function(httpServer, originRegExp) { function ready() { log("ws2mpd attached to a http server", httpServer.address()); } (httpServer.listening ? ready() : httpServer.on("listening", ready)); diff --git a/log.js b/log.js new file mode 100644 index 0000000..5922912 --- /dev/null +++ b/log.js @@ -0,0 +1,8 @@ +function log(...args) { + if (!log.enabled) { return; } + console.log(Date.now(), ...args); +} + +log.enabled = true; + +exports.log = log; \ No newline at end of file