improved logger behaviour and updated default configuration
This commit is contained in:
parent
b8aa962315
commit
4e9273f35c
@ -291,11 +291,6 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
verbose: false,
|
verbose: false,
|
||||||
|
|
||||||
/* RPC errors are shown by default, but if you really don't care,
|
|
||||||
* you can suppress them
|
|
||||||
*/
|
|
||||||
suppressRPCErrors: false,
|
|
||||||
|
|
||||||
/* clients can use the /settings/ app to opt out of usage feedback
|
/* clients can use the /settings/ app to opt out of usage feedback
|
||||||
* which informs the server of things like how much each app is being
|
* which informs the server of things like how much each app is being
|
||||||
* used, and whether certain clientside features are supported by
|
* used, and whether certain clientside features are supported by
|
||||||
|
|||||||
51
lib/log.js
51
lib/log.js
@ -14,6 +14,7 @@ var messageTemplate = function (type, time, tag, info) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var write = function (ctx, content) {
|
var write = function (ctx, content) {
|
||||||
|
if (!ctx.store) { return; }
|
||||||
ctx.store.log(ctx.channelName, content);
|
ctx.store.log(ctx.channelName, content);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -44,7 +45,12 @@ var handlers = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var noop = function () {};
|
||||||
|
|
||||||
var createLogType = function (ctx, type) {
|
var createLogType = function (ctx, type) {
|
||||||
|
if (logLevels.indexOf(type) < logLevels.indexOf(ctx.logLevel)) {
|
||||||
|
return noop;
|
||||||
|
}
|
||||||
return function (tag, info) {
|
return function (tag, info) {
|
||||||
var time = new Date().toISOString();
|
var time = new Date().toISOString();
|
||||||
var content;
|
var content;
|
||||||
@ -53,7 +59,6 @@ var createLogType = function (ctx, type) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.logToStdout && typeof(handlers[type]) === 'function') {
|
if (ctx.logToStdout && typeof(handlers[type]) === 'function') {
|
||||||
handlers[type](ctx, time, tag, info);
|
handlers[type](ctx, time, tag, info);
|
||||||
}
|
}
|
||||||
@ -61,17 +66,29 @@ var createLogType = function (ctx, type) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Log.verbose('THING', x);
|
var createMethods = function (ctx) {
|
||||||
|
var log = {};
|
||||||
|
logLevels.forEach(function (type) {
|
||||||
|
log[type] = createLogType(ctx, type);
|
||||||
|
});
|
||||||
|
return log;
|
||||||
|
};
|
||||||
|
|
||||||
Logger.create = function (config, cb) {
|
Logger.create = function (config, cb) {
|
||||||
if (!config.logPath) {
|
if (typeof(config.logLevel) !== 'string') {
|
||||||
// XXX don't crash, print that you won't log to file
|
config.logLevel = 'info';
|
||||||
throw new Error("Logger: Expected filePath");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* config: {
|
var ctx = {
|
||||||
filePath: '???',
|
channelName: launchTime,
|
||||||
logLevel: 'silly',
|
logFeedback: Boolean(config.logFeedback),
|
||||||
} */
|
logLevel: config.logLevel,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!config.logPath) {
|
||||||
|
console.log("No logPath configured. Logging to file disabled");
|
||||||
|
return void cb(Object.freeze(createMethods(ctx)));
|
||||||
|
}
|
||||||
|
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
var launchTime = ('' + date.getUTCFullYear()).slice(-2) + date.toISOString();
|
var launchTime = ('' + date.getUTCFullYear()).slice(-2) + date.toISOString();
|
||||||
@ -79,20 +96,8 @@ Logger.create = function (config, cb) {
|
|||||||
Store.create({
|
Store.create({
|
||||||
filePath: config.logPath,
|
filePath: config.logPath,
|
||||||
}, function (store) {
|
}, function (store) {
|
||||||
var ctx = {
|
ctx.store = store;
|
||||||
store: store,
|
cb(Object.freeze(createMethods(ctx)));
|
||||||
channelName: launchTime,
|
|
||||||
logFeedback: Boolean(config.logFeedback),
|
|
||||||
// TODO respect configured log settings
|
|
||||||
logLevel: logLevels.indexOf(config.logLevel), // 0 for silly, 1 for debug
|
|
||||||
};
|
|
||||||
|
|
||||||
var log = {};
|
|
||||||
logLevels.forEach(function (type) {
|
|
||||||
log[type] = createLogType(ctx, type);
|
|
||||||
});
|
|
||||||
|
|
||||||
cb(Object.freeze(log));
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
15
rpc.js
15
rpc.js
@ -12,7 +12,7 @@ var Fse = require("fs-extra");
|
|||||||
var Path = require("path");
|
var Path = require("path");
|
||||||
var Https = require("https");
|
var Https = require("https");
|
||||||
const Package = require('./package.json');
|
const Package = require('./package.json');
|
||||||
const Pinned = require('./pinned');
|
const Pinned = require('./scripts/pinned');
|
||||||
const Saferphore = require("saferphore");
|
const Saferphore = require("saferphore");
|
||||||
const nThen = require("nthen");
|
const nThen = require("nthen");
|
||||||
const getFolderSize = require("get-folder-size");
|
const getFolderSize = require("get-folder-size");
|
||||||
@ -25,15 +25,16 @@ var Store = require("./storage/file");
|
|||||||
|
|
||||||
var DEFAULT_LIMIT = 50 * 1024 * 1024;
|
var DEFAULT_LIMIT = 50 * 1024 * 1024;
|
||||||
var SESSION_EXPIRATION_TIME = 60 * 1000;
|
var SESSION_EXPIRATION_TIME = 60 * 1000;
|
||||||
var SUPPRESS_RPC_ERRORS = false;
|
|
||||||
|
|
||||||
var Log;
|
var Log;
|
||||||
|
|
||||||
var WARN = function (e, output) {
|
var WARN = function (e, output) {
|
||||||
if (!SUPPRESS_RPC_ERRORS && e && output) {
|
if (e && output) {
|
||||||
console.error(new Date().toISOString() + ' [' + String(e) + ']', output);
|
Log.warn(e, {
|
||||||
console.error(new Error(e).stack);
|
output: output,
|
||||||
console.error();
|
message: String(e),
|
||||||
|
stack: new Error(e).stack,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1629,8 +1630,6 @@ RPC.create = function (
|
|||||||
// load pin-store...
|
// load pin-store...
|
||||||
Log.silly('LOADING RPC MODULE');
|
Log.silly('LOADING RPC MODULE');
|
||||||
|
|
||||||
if (config.suppressRPCErrors) { SUPPRESS_RPC_ERRORS = true; }
|
|
||||||
|
|
||||||
var keyOrDefaultString = function (key, def) {
|
var keyOrDefaultString = function (key, def) {
|
||||||
return typeof(config[key]) === 'string'? config[key]: def;
|
return typeof(config[key]) === 'string'? config[key]: def;
|
||||||
};
|
};
|
||||||
|
|||||||
12
server.js
12
server.js
@ -243,7 +243,7 @@ httpServer.listen(config.httpPort,config.httpAddress,function(){
|
|||||||
var port = config.httpPort;
|
var port = config.httpPort;
|
||||||
var ps = port === 80? '': ':' + port;
|
var ps = port === 80? '': ':' + port;
|
||||||
|
|
||||||
console.log('\n[%s] server available http://%s%s', new Date().toISOString(), hostName, ps);
|
console.log('[%s] server available http://%s%s', new Date().toISOString(), hostName, ps);
|
||||||
});
|
});
|
||||||
if (config.httpSafePort) {
|
if (config.httpSafePort) {
|
||||||
Http.createServer(app).listen(config.httpSafePort, config.httpAddress);
|
Http.createServer(app).listen(config.httpSafePort, config.httpAddress);
|
||||||
@ -254,17 +254,19 @@ var wsConfig = { server: httpServer };
|
|||||||
var rpc;
|
var rpc;
|
||||||
var historyKeeper;
|
var historyKeeper;
|
||||||
|
|
||||||
|
var log;
|
||||||
|
|
||||||
// Initialize tasks, then rpc, then store, then history keeper and then start the server
|
// Initialize tasks, then rpc, then store, then history keeper and then start the server
|
||||||
var nt = nThen(function (w) {
|
var nt = nThen(function (w) {
|
||||||
// set up logger
|
// set up logger
|
||||||
var Logger = require("./lib/log");
|
var Logger = require("./lib/log");
|
||||||
console.log("Loading logging module");
|
//console.log("Loading logging module");
|
||||||
Logger.create(config, w(function (_log) {
|
Logger.create(config, w(function (_log) {
|
||||||
config.log = _log;
|
log = config.log = _log;
|
||||||
}));
|
}));
|
||||||
}).nThen(function (w) {
|
}).nThen(function (w) {
|
||||||
var Tasks = require("./storage/tasks");
|
var Tasks = require("./storage/tasks");
|
||||||
console.log("loading task scheduler");
|
//log.debug('loading task scheduler');
|
||||||
Tasks.create(config, w(function (e, tasks) {
|
Tasks.create(config, w(function (e, tasks) {
|
||||||
config.tasks = tasks;
|
config.tasks = tasks;
|
||||||
}));
|
}));
|
||||||
@ -297,7 +299,7 @@ var nt = nThen(function (w) {
|
|||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
if (config.useExternalWebsocket) { return; }
|
if (config.useExternalWebsocket) { return; }
|
||||||
if (websocketPort !== config.httpPort) {
|
if (websocketPort !== config.httpPort) {
|
||||||
console.log("setting up a new websocket server");
|
log.debug("setting up a new websocket server");
|
||||||
wsConfig = { port: websocketPort};
|
wsConfig = { port: websocketPort};
|
||||||
}
|
}
|
||||||
var wsSrv = new WebSocketServer(wsConfig);
|
var wsSrv = new WebSocketServer(wsConfig);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user