2016-05-24 16:40:57 +02:00
|
|
|
'use strict';
|
|
|
|
|
2020-04-08 03:19:55 +02:00
|
|
|
const app = require('./app').default;
|
2018-12-17 22:49:54 +01:00
|
|
|
const config = require('./config').config;
|
2016-05-24 16:40:57 +02:00
|
|
|
|
2016-05-24 19:14:09 +02:00
|
|
|
// Hack to allow proper logging of Error.
|
|
|
|
Object.defineProperty(Error.prototype, 'message', {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true
|
|
|
|
});
|
|
|
|
Object.defineProperty(Error.prototype, 'stack', {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true
|
2016-05-24 16:40:57 +02:00
|
|
|
});
|
|
|
|
|
2016-05-24 19:14:09 +02:00
|
|
|
|
2018-12-17 22:49:54 +01:00
|
|
|
const scribe = require('scribe-js')({
|
2016-05-24 19:14:09 +02:00
|
|
|
rootPath: config.server.logging.directory,
|
2016-05-24 16:40:57 +02:00
|
|
|
});
|
|
|
|
|
2016-07-29 12:53:20 +02:00
|
|
|
function addLogger(name, color, active) {
|
|
|
|
if (active) {
|
|
|
|
process.console.addLogger(name, color, {
|
|
|
|
logInConsole: false
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
process.console[name] = function () {
|
|
|
|
this._reset(); // forget tags, etc. for this logging event
|
|
|
|
};
|
|
|
|
}
|
2016-05-24 19:14:09 +02:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:53:20 +02:00
|
|
|
addLogger('debug', 'grey', config.server.logging.debug);
|
|
|
|
addLogger('profile', 'blue', config.server.logging.profile);
|
|
|
|
|
2018-12-17 22:49:54 +01:00
|
|
|
if (config.server.logging.logRequests) {
|
|
|
|
app.use(scribe.express.logger());
|
|
|
|
}
|
|
|
|
if (config.server.internal.active) {
|
|
|
|
const prefix = config.server.rootPath === '/' ? '' : config.server.rootPath;
|
|
|
|
app.use(prefix + '/internal/logs', scribe.webPanel());
|
|
|
|
}
|
2016-05-24 16:40:57 +02:00
|
|
|
|
2018-12-17 22:49:54 +01:00
|
|
|
// Hack to allow correct logging of node.js Error objects.
|
|
|
|
// See: https://github.com/bluejamesbond/Scribe.js/issues/70
|
|
|
|
Object.defineProperty(Error.prototype, 'toJSON', {
|
|
|
|
configurable: true,
|
|
|
|
value: function () {
|
|
|
|
const alt = {};
|
|
|
|
const storeKey = function (key) {
|
|
|
|
alt[key] = this[key];
|
|
|
|
};
|
|
|
|
Object.getOwnPropertyNames(this).forEach(storeKey, this);
|
|
|
|
return alt;
|
|
|
|
}
|
2016-05-24 16:40:57 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = process.console;
|