0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

🎨 Add support for short one-line log format (#7523)

refs #7116

- The long format logs were making it hard to see the debug statements
- Seeing headers for every asset is a bit much
- "short" format doesn't output bodyPretty
- This needs love as there's no reason to calculate bodyPretty if we aren't using it
- The default output should be discussed
- req.url doesn't include the full path when apps are mounted
- Use mode instead of format & pass config correctly
This commit is contained in:
Hannah Wolfe 2016-10-10 15:17:16 +01:00 committed by Katharina Irrgang
parent c4fa34224f
commit d979bd442e
3 changed files with 25 additions and 21 deletions

View file

@ -113,7 +113,7 @@ GhostLogger.prototype.setStreams = function setStreams() {
}
if (transport === 'stdout') {
prettyStdOut = new GhostPrettyStream();
prettyStdOut = new GhostPrettyStream({mode: self.mode});
prettyStdOut.pipe(process.stdout);
streams.push({

View file

@ -40,7 +40,8 @@ var _ = require('lodash'),
};
function PrettyStream() {
function PrettyStream(options) {
this.mode = options.mode || 'short';
}
util.inherits(PrettyStream, Stream);
@ -59,7 +60,8 @@ PrettyStream.prototype.write = function write(data) {
}
}
var body = {},
var output = '',
body = {},
time = moment(data.time).format('YYYY-MM-DD HH:mm:ss'),
logLevel = __private__.levelFromName[data.level].toUpperCase(),
codes = __private__.colors[__private__.colorForLevel[data.level]],
@ -74,12 +76,11 @@ PrettyStream.prototype.write = function write(data) {
if (data.req && data.res) {
_.each(data.req, function (value, key) {
if (['headers', 'query', 'body'].indexOf(key) !== -1 && !_.isEmpty(value)) {
bodyPretty += colorize('yellow', key.toUpperCase()) + '\n';
bodyPretty += '\n' + colorize('yellow', key.toUpperCase()) + '\n';
bodyPretty += prettyjson.render(value, {}) + '\n';
}
});
bodyPretty += '\n';
if (data.err) {
if (data.err.level) {
bodyPretty += colorize('yellow', 'ERROR (' + data.err.level + ')') + '\n';
@ -100,7 +101,7 @@ PrettyStream.prototype.write = function write(data) {
}
if (key === 'level') {
bodyPretty += colorize('underline', key + ':' + value) + '\n\n';
bodyPretty += colorize('underline', key + ':' + value) + '\n';
}
else if (key === 'message') {
bodyPretty += colorize('red', value) + '\n';
@ -122,27 +123,31 @@ PrettyStream.prototype.write = function write(data) {
try {
if (data.req && data.res) {
this.emit('data', format('[%s] %s --> %s %s (%s) \n%s\n\n',
output += format('[%s] %s %s %s (%s)\n',
time,
logLevel,
data.req.method,
data.req.url,
data.res.statusCode,
colorize('grey', bodyPretty)
));
data.req.originalUrl,
data.res.statusCode
);
} else if (data.err) {
this.emit('data', format('[%s] %s \n%s\n\n',
output += format('[%s] %s\n',
time,
logLevel,
colorize('grey', bodyPretty)
));
logLevel
);
} else {
this.emit('data', format('[%s] %s %s\n',
output += format('[%s] %s\n',
time,
logLevel,
colorize('grey', bodyPretty)
));
logLevel
);
}
if (this.mode !== 'short' && bodyPretty) {
output += format('%s\n', colorize('grey', bodyPretty));
}
this.emit('data', output);
} catch (err) {
this.emit('data', err);
}
@ -150,5 +155,4 @@ PrettyStream.prototype.write = function write(data) {
return true;
};
module.exports = PrettyStream;

View file

@ -2,7 +2,7 @@ var config = require('../config'),
GhostLogger = require('./GhostLogger'),
adapter = new GhostLogger({
env: config.get('env'),
mode: process.env.NODE_MODE,
mode: process.env.NODE_MODE || config.get('logging:mode'),
level: process.env.NODE_LEVEL || config.get('logging:level'),
transports: config.get('logging:transports'),
rotation: config.get('logging:rotation'),