logging
This commit is contained in:
parent
5afd07ea64
commit
6e228df0fc
3 changed files with 14 additions and 8 deletions
|
@ -1,8 +1,5 @@
|
||||||
const EventEmitter = require("events");
|
const EventEmitter = require("events");
|
||||||
|
const log = require("./log.js").log;
|
||||||
function log(...args) {
|
|
||||||
console.log(Date.now(), ...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
class Command extends EventEmitter {
|
class Command extends EventEmitter {
|
||||||
constructor(mpd) {
|
constructor(mpd) {
|
||||||
|
|
9
index.js
9
index.js
|
@ -1,10 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
const commands = require("./commands");
|
const commands = require("./commands");
|
||||||
|
const log = require("./log.js").log;
|
||||||
function log(...args) {
|
|
||||||
console.log(Date.now(), ...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
function initConnection(request) {
|
function initConnection(request) {
|
||||||
let ws = request.accept();
|
let ws = request.accept();
|
||||||
|
@ -62,6 +59,10 @@ function initConnection(request) {
|
||||||
waitForCommand(commands.welcome(mpd));
|
waitForCommand(commands.welcome(mpd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.logging = function(enabled) {
|
||||||
|
log.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
exports.ws2mpd = function(httpServer, originRegExp) {
|
exports.ws2mpd = function(httpServer, originRegExp) {
|
||||||
function ready() { log("ws2mpd attached to a http server", httpServer.address()); }
|
function ready() { log("ws2mpd attached to a http server", httpServer.address()); }
|
||||||
(httpServer.listening ? ready() : httpServer.on("listening", ready));
|
(httpServer.listening ? ready() : httpServer.on("listening", ready));
|
||||||
|
|
8
log.js
Normal file
8
log.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
function log(...args) {
|
||||||
|
if (!log.enabled) { return; }
|
||||||
|
console.log(Date.now(), ...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.enabled = true;
|
||||||
|
|
||||||
|
exports.log = log;
|
Loading…
Reference in a new issue