Repository URL to install this package:
|
Version:
0.0.1-b0bdfbe435df1c ▾
|
#!/usr/bin/env node
const readline = require('readline');
const level = require('./level');
const options = require('./options');
const { layout } = require('./constants');
const genericFormatter = require('./component/background-text');
const severityComp = require('./component/severity');
const messageComp = require('./component/message');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
const printDefaultLayout = (log, normalizedSeverity) => {
const separator = genericFormatter.format('-', normalizedSeverity);
const severity = severityComp.format(normalizedSeverity);
const instant = genericFormatter.format(log.apptime, normalizedSeverity);
const message = messageComp.format(log.message, normalizedSeverity);
const clazz = genericFormatter.format(log.class, normalizedSeverity);
const thread = genericFormatter.format(log.thread, normalizedSeverity);
const exception = log.ex ? genericFormatter.format(log.ex, normalizedSeverity) : null
let prettyLog = `${instant} ${separator} ${clazz} ${separator} ${thread}\n${severity} ${message}`;
prettyLog = exception ? `${prettyLog}\n${exception}\n` : `${prettyLog}\n`;
console.log(prettyLog)
}
rl.on('line', function(line) {
let log;
try {
log = JSON.parse(line);
} catch (e) {
// the SpringBoot banner is not a valid JSON, but we can ignore it here
// console.log(e);
return;
}
const normalizedSeverity = log.severity.trim().toLowerCase();
if (!level.shouldDisplay(normalizedSeverity, options.minimumSeverityToDisplay)) {
return;
}
printDefaultLayout(log, normalizedSeverity);
});