quieter stdout and stderr logs

This commit is contained in:
ansuz 2016-09-30 15:51:23 +02:00
parent bc73fa2074
commit 4b238de84c
4 changed files with 13 additions and 30 deletions

View File

@ -1,8 +1,6 @@
;(function () { 'use strict'; ;(function () { 'use strict';
const Crypto = require('crypto'); const Crypto = require('crypto');
const Nacl = require('tweetnacl'); const Nacl = require('tweetnacl');
const LogStore = require('./storage/LogStore');
const LAG_MAX_BEFORE_DISCONNECT = 30000; const LAG_MAX_BEFORE_DISCONNECT = 30000;
const LAG_MAX_BEFORE_PING = 15000; 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_HISTORY_KEEPER = true;
const USE_FILE_BACKUP_STORAGE = true; const USE_FILE_BACKUP_STORAGE = true;
let dropUser; let dropUser;
let historyKeeperKeys = {}; let historyKeeperKeys = {};
@ -79,10 +76,15 @@ dropUser = function (ctx, user) {
let chan = ctx.channels[chanName]; let chan = ctx.channels[chanName];
let idx = chan.indexOf(user); let idx = chan.indexOf(user);
if (idx < 0) { return; } 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); chan.splice(idx, 1);
if (chan.length === 0) { if (chan.length === 0) {
console.log("Removing empty channel ["+chanName+"]"); if (ctx.verbose) {
console.log("Removing empty channel ["+chanName+"]");
}
delete ctx.channels[chanName]; delete ctx.channels[chanName];
delete historyKeeperKeys[chanName]; delete historyKeeperKeys[chanName];
@ -94,7 +96,9 @@ dropUser = function (ctx, user) {
ctx.store.removeChannel(chanName, function (err) { ctx.store.removeChannel(chanName, function (err) {
if (err) { console.error("[removeChannelErr]: %s", err); } if (err) { console.error("[removeChannelErr]: %s", err); }
else { 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); }, ctx.config.channelRemovalTimeout);
@ -253,7 +257,7 @@ let run = module.exports.run = function (storage, socketServer, config) {
users: {}, users: {},
channels: {}, channels: {},
timeouts: {}, timeouts: {},
store: (USE_FILE_BACKUP_STORAGE) ? LogStore.create('messages.log', storage) : storage, store: storage,
config: config config: config
}; };
setInterval(function () { setInterval(function () {

View File

@ -66,7 +66,7 @@ app.get('/api/config', function(req, res){
var httpServer = httpsOpts ? Https.createServer(httpsOpts, app) : Http.createServer(app); var httpServer = httpsOpts ? Https.createServer(httpsOpts, app) : Http.createServer(app);
httpServer.listen(config.httpPort,config.httpAddress,function(){ 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 }; var wsConfig = { server: httpServer };
@ -76,7 +76,6 @@ if (config.websocketPort !== config.httpPort) {
} }
var wsSrv = new WebSocketServer(wsConfig); var wsSrv = new WebSocketServer(wsConfig);
Storage.create(config, function (store) { Storage.create(config, function (store) {
console.log('DB connected');
NetfluxSrv.run(store, wsSrv, config); NetfluxSrv.run(store, wsSrv, config);
WebRTCSrv.run(wsSrv); WebRTCSrv.run(wsSrv);
}); });

View File

@ -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;
};

View File

@ -171,7 +171,6 @@ module.exports.create = function (conf, cb) {
root: conf.filePath || './datastore', root: conf.filePath || './datastore',
channels: { }, channels: { },
}; };
console.log('storing data in ' + env.root);
Fs.mkdir(env.root, function (err) { Fs.mkdir(env.root, function (err) {
if (err && err.code !== 'EEXIST') { if (err && err.code !== 'EEXIST') {
// TODO: somehow return a nice error // TODO: somehow return a nice error