diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-12-12 23:19:01 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-12-25 11:09:16 +0100 |
commit | a03458396b35c455f01a7429456fd8f0b5d7a4f4 (patch) | |
tree | 0a513b4860263bf6d8d8bbcedeb0292c4fee8373 /lib/internal/util/debuglog.js | |
parent | be3c7aceba58f0a58ee4813a9894681d9c8ba56e (diff) | |
download | node-new-a03458396b35c455f01a7429456fd8f0b5d7a4f4.tar.gz |
util: add colors to debuglog()
This adds colors to the passed through arguments in case the stream
supports colors. The PID will also be highlighted.
PR-URL: https://github.com/nodejs/node/pull/30930
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/util/debuglog.js')
-rw-r--r-- | lib/internal/util/debuglog.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/internal/util/debuglog.js b/lib/internal/util/debuglog.js index 87af5de833..9834668307 100644 --- a/lib/internal/util/debuglog.js +++ b/lib/internal/util/debuglog.js @@ -1,6 +1,6 @@ 'use strict'; -const { format } = require('internal/util/inspect'); +const { inspect, format, formatWithOptions } = require('internal/util/inspect'); // `debugs` is deliberately initialized to undefined so any call to // debuglog() before initializeDebugEnv() is called will throw. @@ -38,8 +38,10 @@ function debuglogImpl(set) { const pid = process.pid; emitWarningIfNeeded(set); debugs[set] = function debug(...args) { - const msg = format(...args); - process.stderr.write(format('%s %d: %s\n', set, pid, msg)); + const colors = process.stderr.hasColors && process.stderr.hasColors(); + const msg = formatWithOptions({ colors }, ...args); + const coloredPID = inspect(pid, { colors }); + process.stderr.write(format('%s %s: %s\n', set, coloredPID, msg)); }; } else { debugs[set] = null; |