Split out web logging to it's own logger/files/configuration
This commit is contained in:
parent
d286fa2cf4
commit
8a4f90263a
|
@ -302,6 +302,17 @@ module.exports = () => {
|
||||||
|
|
||||||
staticRoot: paths.join(__dirname, './../www'),
|
staticRoot: paths.join(__dirname, './../www'),
|
||||||
|
|
||||||
|
// Logging block works the same way the system logger does
|
||||||
|
logging: {
|
||||||
|
rotatingFile: {
|
||||||
|
level: 'info',
|
||||||
|
type: 'rotating-file',
|
||||||
|
fileName: 'enigma-bbs.web.log',
|
||||||
|
period: '1d',
|
||||||
|
count: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
handlers: {
|
handlers: {
|
||||||
systemGeneral: {
|
systemGeneral: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|
|
@ -27,6 +27,16 @@ module.exports = class Log {
|
||||||
logStreams.push(Config.logging.rotatingFile);
|
logStreams.push(Config.logging.rotatingFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const serializers = Log.standardSerializers();
|
||||||
|
|
||||||
|
this.log = bunyan.createLogger({
|
||||||
|
name: 'ENiGMA½ BBS',
|
||||||
|
streams: logStreams,
|
||||||
|
serializers: serializers,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static standardSerializers() {
|
||||||
const serializers = {
|
const serializers = {
|
||||||
err: bunyan.stdSerializers.err, // handle 'err' fields with stack/etc.
|
err: bunyan.stdSerializers.err, // handle 'err' fields with stack/etc.
|
||||||
};
|
};
|
||||||
|
@ -36,11 +46,7 @@ module.exports = class Log {
|
||||||
serializers[keyName] = fd => Log.hideSensitive(fd);
|
serializers[keyName] = fd => Log.hideSensitive(fd);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.log = bunyan.createLogger({
|
return serializers;
|
||||||
name: 'ENiGMA½ BBS',
|
|
||||||
streams: logStreams,
|
|
||||||
serializers: serializers,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static checkLogPath(logPath) {
|
static checkLogPath(logPath) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ const paths = require('path');
|
||||||
const mimeTypes = require('mime-types');
|
const mimeTypes = require('mime-types');
|
||||||
const forEachSeries = require('async/forEachSeries');
|
const forEachSeries = require('async/forEachSeries');
|
||||||
const findSeries = require('async/findSeries');
|
const findSeries = require('async/findSeries');
|
||||||
|
const WebLog = require('../../web_log.js');
|
||||||
|
|
||||||
const ModuleInfo = (exports.moduleInfo = {
|
const ModuleInfo = (exports.moduleInfo = {
|
||||||
name: 'Web',
|
name: 'Web',
|
||||||
|
@ -74,7 +75,8 @@ exports.getModule = class WebServerModule extends ServerModule {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.log = Log.child({ server: 'Web' });
|
//this.log = Log.child({ server: 'Web' });
|
||||||
|
this.log = WebLog.createWebLog();
|
||||||
|
|
||||||
const config = Config();
|
const config = Config();
|
||||||
this.enableHttp = config.contentServers.web.http.enabled || false;
|
this.enableHttp = config.contentServers.web.http.enabled || false;
|
||||||
|
@ -276,7 +278,7 @@ exports.getModule = class WebServerModule extends ServerModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
routeRequest(req, resp) {
|
routeRequest(req, resp) {
|
||||||
this.log.trace({ url: req.url, method: req.method }, 'Request');
|
this.log.trace({ req }, 'Request');
|
||||||
|
|
||||||
let route = _.find(this.routes, r => r.matchesRequest(req));
|
let route = _.find(this.routes, r => r.matchesRequest(req));
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ exports.getModule = class NodeInfo2WebHadnler extends WebHandlerModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
_nodeInfo2Handler(req, resp) {
|
_nodeInfo2Handler(req, resp) {
|
||||||
this.log.info({ url: req.url }, 'Serving NodeInfo2 request');
|
this.log.info('Serving NodeInfo2 request');
|
||||||
|
|
||||||
this._getNodeInfo(nodeInfo => {
|
this._getNodeInfo(nodeInfo => {
|
||||||
const body = JSON.stringify(nodeInfo);
|
const body = JSON.stringify(nodeInfo);
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
const Logger = require('./logger');
|
||||||
|
const Config = require('./config').get;
|
||||||
|
|
||||||
|
// deps
|
||||||
|
const paths = require('path');
|
||||||
|
const bunyan = require('bunyan');
|
||||||
|
const { get } = require('lodash');
|
||||||
|
|
||||||
|
module.exports = class WebLog {
|
||||||
|
static createWebLog() {
|
||||||
|
const config = Config();
|
||||||
|
const logPath = config.paths.logs;
|
||||||
|
const rotatingFile = get(config, 'contentServers.web.logging.rotatingFile');
|
||||||
|
|
||||||
|
rotatingFile.path = paths.join(logPath, rotatingFile.fileName);
|
||||||
|
|
||||||
|
const serializers = Logger.standardSerializers();
|
||||||
|
serializers.req = bunyan.stdSerializers.req;
|
||||||
|
serializers.res = bunyan.stdSerializers.res;
|
||||||
|
|
||||||
|
const webLog = bunyan.createLogger({
|
||||||
|
name: 'ENiGMA½ BBS[Web]',
|
||||||
|
streams: [rotatingFile],
|
||||||
|
serializers,
|
||||||
|
});
|
||||||
|
|
||||||
|
return webLog;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue