From 6869931a606b37eae5f41180d0d228f550fe3916 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Tue, 6 Nov 2012 12:50:39 -0800 Subject: [PATCH] issue #55: add BUNYAN_NO_COLOR envvar support --- CHANGES.md | 4 +++- bin/bunyan | 14 +++++++++++++- docs/bunyan.1 | 6 ++++++ docs/bunyan.1.html | 8 ++++++++ docs/bunyan.1.ronn | 6 ++++++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 05e3554..daa0663 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,9 @@ ## bunyan 0.16.5 (not yet released) -(nothing yet) +- issue #55: Add support for `BUNYAN_NO_COLOR` environment variable to + turn off all output coloring. This is still overridden by the `--color` + and `--no-color` options. ## bunyan 0.16.4 diff --git a/bin/bunyan b/bin/bunyan index 16ab571..12cb087 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -191,6 +191,10 @@ function printHelp() { console.log(" %s %d", n, levelFromName[name]); }); console.log(""); + console.log("Environment Variables:"); + console.log(" BUNYAN_NO_COLOR Set to a non-empty value to force no output "); + console.log(" coloring. See '--no-color'."); + console.log(""); console.log("See for more complete docs."); console.log("Please report bugs to ."); } @@ -314,7 +318,7 @@ function parseArgv(argv) { var parsed = { args: [], help: false, - color: process.stdout.isTTY, + color: null, outputMode: OM_PAUL, jsonIndent: 2, level: null, @@ -1114,6 +1118,14 @@ function main(argv) { opts.pid, opts.args.join(' ')); return drainStdoutAndExit(1); } + if (opts.color === null) { + if (process.env.BUNYAN_NO_COLOR && + process.env.BUNYAN_NO_COLOR.length > 0) { + opts.color = false; + } else { + opts.color = process.stdout.isTTY; + } + } var stylize = (opts.color ? stylizeWithColor : stylizeWithoutColor); var retval = 0; diff --git a/docs/bunyan.1 b/docs/bunyan.1 index 48cf235..a826c98 100644 --- a/docs/bunyan.1 +++ b/docs/bunyan.1 @@ -197,6 +197,12 @@ Each of these probes has a single argument: the string that would be written to .P See \fIhttps://github\.com/trentm/node\-bunyan#dtrace\-support\fR for more details\. . +.SH "ENVIRONMENT" +. +.TP +\fBBUNYAN_NO_COLOR\fR +Set to a non\-empty value to force no output coloring\. See \'\-\-no\-color\'\. +. .SH "PROJECT & BUGS" \fBbunyan\fR is written in JavaScript and requires node\.js (\fBnode\fR)\. The project lives at \fIhttps://github\.com/trentm/node\-bunyan\fR and is published to npm as "bunyan"\. . diff --git a/docs/bunyan.1.html b/docs/bunyan.1.html index ca48260..70577fb 100644 --- a/docs/bunyan.1.html +++ b/docs/bunyan.1.html @@ -66,6 +66,7 @@ LOG LEVELS OUTPUT FORMATS DTRACE SUPPORT + ENVIRONMENT PROJECT & BUGS LICENSE COPYRIGHT @@ -230,6 +231,13 @@ the log message is less than that of any stream.

See https://github.com/trentm/node-bunyan#dtrace-support for more details.

+

ENVIRONMENT

+ +
+
BUNYAN_NO_COLOR
Set to a non-empty value to force no output coloring. See '--no-color'.
+
+ +

PROJECT & BUGS

bunyan is written in JavaScript and requires node.js (node). The project diff --git a/docs/bunyan.1.ronn b/docs/bunyan.1.ronn index 1c77be8..7eee448 100644 --- a/docs/bunyan.1.ronn +++ b/docs/bunyan.1.ronn @@ -156,6 +156,12 @@ the log message is less than that of any stream. See for more details. +## ENVIRONMENT + + * `BUNYAN_NO_COLOR`: + Set to a non-empty value to force no output coloring. See '--no-color'. + + ## PROJECT & BUGS `bunyan` is written in JavaScript and requires node.js (`node`). The project