Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "tiny" output for CLI #389

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions bin/bunyan
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ var OM_INSPECT = 3;
var OM_SIMPLE = 4;
var OM_SHORT = 5;
var OM_BUNYAN = 6;
var OM_TINY = 7;
var OM_FROM_NAME = {
'long': OM_LONG,
'paul': OM_LONG, /* backward compat */
'json': OM_JSON,
'inspect': OM_INSPECT,
'simple': OM_SIMPLE,
'short': OM_SHORT,
'bunyan': OM_BUNYAN
'bunyan': OM_BUNYAN,
'tiny': OM_TINY
};


Expand Down Expand Up @@ -244,6 +246,7 @@ function printHelp() {
p(' bunyan: 0 indented JSON, bunyan\'s native format');
p(' inspect: node.js `util.inspect` output');
p(' short: like "long", but more concise');
p(' tiny: like "long", but message only');
p(' -j shortcut for `-o json`');
p(' -0 shortcut for `-o bunyan`');
p(' -L, --time local');
Expand Down Expand Up @@ -750,8 +753,13 @@ function handleLogLine(file, line, opts, stylize) {
*/
function emitRecord(rec, line, opts, stylize) {
var short = false;
var tiny = false;

switch (opts.outputMode) {
case OM_TINY:
tiny = true;
/* jsl:fall-thru */

case OM_SHORT:
short = true;
/* jsl:fall-thru */
Expand Down Expand Up @@ -849,9 +857,10 @@ function emitRecord(rec, line, opts, stylize) {
}
delete rec.req_id;

var onelineMsg;
if (rec.msg.indexOf('\n') !== -1) {
onelineMsg = '';
var onelineMsg = '';
if (tiny) {
onelineMsg = stylize(rec.msg, 'cyan');
} else if (rec.msg.indexOf('\n') !== -1) {
details.push(indent(stylize(rec.msg, 'cyan')));
} else {
onelineMsg = ' ' + stylize(rec.msg, 'cyan');
Expand Down Expand Up @@ -1045,21 +1054,26 @@ function emitRecord(rec, line, opts, stylize) {
(extras.length ? ' (' + extras.join(', ') + ')' : ''), 'XXX');
details = stylize(
(details.length ? details.join('\n --\n') + '\n' : ''), 'XXX');
if (!short)
emit(format('%s %s: %s on %s%s:%s%s\n%s',
if (tiny)
emit(format('%s%s\n%s',
onelineMsg,
extras,
details));
else if (short)
emit(format('%s %s %s:%s%s\n%s',
time,
level,
nameStr,
hostname || '<no-hostname>',
src,
onelineMsg,
extras,
details));
else
emit(format('%s %s %s:%s%s\n%s',
emit(format('%s %s: %s on %s%s:%s%s\n%s',
time,
level,
nameStr,
hostname || '<no-hostname>',
src,
onelineMsg,
extras,
details));
Expand Down