From 4b238de84c4922c099fdbbdf273a1789980174b0 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 30 Sep 2016 15:51:23 +0200 Subject: [PATCH] quieter stdout and stderr logs --- NetfluxWebsocketSrv.js | 18 +++++++++++------- server.js | 5 ++--- storage/LogStore.js | 19 ------------------- storage/file.js | 1 - 4 files changed, 13 insertions(+), 30 deletions(-) delete mode 100644 storage/LogStore.js diff --git a/NetfluxWebsocketSrv.js b/NetfluxWebsocketSrv.js index bfb8e4753..98d79f72f 100644 --- a/NetfluxWebsocketSrv.js +++ b/NetfluxWebsocketSrv.js @@ -1,8 +1,6 @@ ;(function () { 'use strict'; const Crypto = require('crypto'); const Nacl = require('tweetnacl'); -const LogStore = require('./storage/LogStore'); - const LAG_MAX_BEFORE_DISCONNECT = 30000; const LAG_MAX_BEFORE_PING = 15000; @@ -11,7 +9,6 @@ const HISTORY_KEEPER_ID = Crypto.randomBytes(8).toString('hex'); const USE_HISTORY_KEEPER = true; const USE_FILE_BACKUP_STORAGE = true; - let dropUser; let historyKeeperKeys = {}; @@ -79,10 +76,15 @@ dropUser = function (ctx, user) { let chan = ctx.channels[chanName]; let idx = chan.indexOf(user); if (idx < 0) { return; } - console.log("Removing ["+user.id+"] from channel ["+chanName+"]"); + + if (ctx.verbose) { + console.log("Removing ["+user.id+"] from channel ["+chanName+"]"); + } chan.splice(idx, 1); if (chan.length === 0) { - console.log("Removing empty channel ["+chanName+"]"); + if (ctx.verbose) { + console.log("Removing empty channel ["+chanName+"]"); + } delete ctx.channels[chanName]; delete historyKeeperKeys[chanName]; @@ -94,7 +96,9 @@ dropUser = function (ctx, user) { ctx.store.removeChannel(chanName, function (err) { if (err) { console.error("[removeChannelErr]: %s", err); } else { - console.log("Deleted channel [%s] history from database...", chanName); + if (ctx.verbose) { + console.log("Deleted channel [%s] history from database...", chanName); + } } }); }, ctx.config.channelRemovalTimeout); @@ -253,7 +257,7 @@ let run = module.exports.run = function (storage, socketServer, config) { users: {}, channels: {}, timeouts: {}, - store: (USE_FILE_BACKUP_STORAGE) ? LogStore.create('messages.log', storage) : storage, + store: storage, config: config }; setInterval(function () { diff --git a/server.js b/server.js index e05606374..c490698b3 100644 --- a/server.js +++ b/server.js @@ -66,7 +66,7 @@ app.get('/api/config', function(req, res){ var httpServer = httpsOpts ? Https.createServer(httpsOpts, app) : Http.createServer(app); httpServer.listen(config.httpPort,config.httpAddress,function(){ - console.log('listening on %s',config.httpPort); + console.log('[%s] listening on port %s', new Date().toISOString(), config.httpPort); }); var wsConfig = { server: httpServer }; @@ -76,7 +76,6 @@ if (config.websocketPort !== config.httpPort) { } var wsSrv = new WebSocketServer(wsConfig); Storage.create(config, function (store) { - console.log('DB connected'); NetfluxSrv.run(store, wsSrv, config); WebRTCSrv.run(wsSrv); -}); \ No newline at end of file +}); diff --git a/storage/LogStore.js b/storage/LogStore.js deleted file mode 100644 index 14761e6b7..000000000 --- a/storage/LogStore.js +++ /dev/null @@ -1,19 +0,0 @@ -var Fs = require("fs"); - -var message = function(file, msg) { - file.write(msg+"\n"); -}; - -var create = module.exports.create = function(filePath, backingStore) { - - var file = Fs.createWriteStream(filePath, {flags: 'a+'}); - - var originalMessageFunction = backingStore.message; - - backingStore.message = function(channel, msg, callback) { - message(file, msg); - originalMessageFunction(channel, msg, callback); - }; - - return backingStore; -}; diff --git a/storage/file.js b/storage/file.js index 7503791a8..162894b63 100644 --- a/storage/file.js +++ b/storage/file.js @@ -171,7 +171,6 @@ module.exports.create = function (conf, cb) { root: conf.filePath || './datastore', channels: { }, }; - console.log('storing data in ' + env.root); Fs.mkdir(env.root, function (err) { if (err && err.code !== 'EEXIST') { // TODO: somehow return a nice error