mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-03-18 02:22:46 -05:00
don't print colors if output stream is not tty
This commit is contained in:
parent
015623f9ae
commit
fcebeea3ee
1 changed files with 20 additions and 8 deletions
|
@ -34,7 +34,7 @@ module.exports.setup = function(logs) {
|
|||
if (target.format === 'pretty') {
|
||||
// making fake stream for prettypritting
|
||||
stream.write = function(obj) {
|
||||
dest.write(print(obj.level, obj.msg, obj) + "\n");
|
||||
dest.write(print(obj.level, obj.msg, obj, dest.isTTY) + "\n");
|
||||
}
|
||||
} else {
|
||||
stream.write = function(obj) {
|
||||
|
@ -101,14 +101,19 @@ function pad(str) {
|
|||
return str;
|
||||
};
|
||||
|
||||
var subsystems = {
|
||||
var subsystems = [{
|
||||
in: '\x1b[32m<--\x1b[39m',
|
||||
out: '\x1b[33m-->\x1b[39m',
|
||||
fs: '\x1b[37m-*-\x1b[39m',
|
||||
default: '\x1b[34m---\x1b[39m',
|
||||
};
|
||||
}, {
|
||||
in: '<--',
|
||||
out: '-->',
|
||||
fs: '-*-',
|
||||
default: '---',
|
||||
}];
|
||||
|
||||
function print(type, msg, obj) {
|
||||
function print(type, msg, obj, colors) {
|
||||
if (typeof type === 'number') type = getlvl(type);
|
||||
var finalmsg = msg.replace(/@{(!?[$A-Za-z_][$0-9A-Za-z\._]*)}/g, function(_, name) {
|
||||
var str = obj, is_error;
|
||||
|
@ -128,17 +133,24 @@ function print(type, msg, obj) {
|
|||
}
|
||||
|
||||
if (typeof(str) === 'string') {
|
||||
if (is_error) {
|
||||
if (!colors) {
|
||||
return str;
|
||||
} else if (is_error) {
|
||||
return '\x1b[31m' + str + '\x1b[39m';
|
||||
} else {
|
||||
return '\x1b[32m' + str + '\x1b[39m';
|
||||
}
|
||||
} else {
|
||||
return require('util').inspect(str, void 0, void 0, true);
|
||||
return require('util').inspect(str, void 0, void 0, colors);
|
||||
}
|
||||
});
|
||||
var sub = subsystems[obj.sub] || subsystems.default;
|
||||
var sub = subsystems[+!colors][obj.sub] || subsystems[+!colors].default;
|
||||
// ^^--- black magic... kidding, just "colors ? 0 : 1"
|
||||
|
||||
return " \x1b[" + levels[type] + "m" + (pad(type)) + "\x1b[39m " + sub + " " + finalmsg;
|
||||
if (colors) {
|
||||
return " \x1b[" + levels[type] + "m" + (pad(type)) + "\x1b[39m " + sub + " " + finalmsg;
|
||||
} else {
|
||||
return " " + (pad(type)) + " " + sub + " " + finalmsg;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue