Skip to content

Commit e9051da

Browse files
committed
Added environment DEBUG_TIMESTAMPS to enable turning off timestamps when useColors is false.
1 parent 13e1d06 commit e9051da

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/debug.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ function createDebug(namespace) {
118118
debug.namespace = namespace;
119119
debug.enabled = exports.enabled(namespace);
120120
debug.useColors = exports.useColors();
121+
debug.printTimestamp = exports.printTimestamp ? exports.printTimestamp() : true;
121122
debug.color = selectColor(namespace);
122123
debug.destroy = destroy;
123124

src/node.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ exports.formatArgs = formatArgs;
1818
exports.save = save;
1919
exports.load = load;
2020
exports.useColors = useColors;
21+
exports.printTimestamp = printTimestamp;
2122

2223
/**
2324
* Colors.
@@ -43,7 +44,7 @@ try {
4344
/**
4445
* Build up the default `inspectOpts` object from the environment variables.
4546
*
46-
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
47+
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled DEBUG_TIMESTAMPS=no node script.js
4748
*/
4849

4950
exports.inspectOpts = Object.keys(process.env).filter(function (key) {
@@ -76,6 +77,17 @@ function useColors() {
7677
: tty.isatty(process.stderr.fd);
7778
}
7879

80+
/**
81+
* Print timestamps when useColours() is false. This flag enables
82+
* timestamps to be turned off when useColours() is false.
83+
*/
84+
85+
function printTimestamp() {
86+
return 'timestamps' in exports.inspectOpts
87+
? Boolean(exports.inspectOpts.timestamps)
88+
: true;
89+
}
90+
7991
/**
8092
* Map %o to `util.inspect()`, all on a single line.
8193
*/
@@ -104,6 +116,7 @@ exports.formatters.O = function(v) {
104116
function formatArgs(args) {
105117
var name = this.namespace;
106118
var useColors = this.useColors;
119+
var printTimestamp = this.printTimestamp;
107120

108121
if (useColors) {
109122
var c = this.color;
@@ -112,9 +125,11 @@ function formatArgs(args) {
112125

113126
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
114127
args.push(colorCode + 'm+' + exports.humanize(this.diff) + '\u001b[0m');
115-
} else {
128+
} else if (printTimestamp) {
116129
args[0] = new Date().toISOString()
117130
+ ' ' + name + ' ' + args[0];
131+
} else {
132+
args[0] = name + ' ' + args[0];
118133
}
119134
}
120135

0 commit comments

Comments
 (0)