Skip to content

Commit

Permalink
Merge 12b708e into d17973c
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk committed Dec 22, 2018
2 parents d17973c + 12b708e commit e8584af
Show file tree
Hide file tree
Showing 3 changed files with 337 additions and 8 deletions.
35 changes: 27 additions & 8 deletions index.js
Expand Up @@ -5,16 +5,20 @@ var gray = require('ansi-gray');
var timestamp = require('time-stamp');
var supportsColor = require('color-support');
var nodeVersion = require('parse-node-version')(process.version);
var themingLog = require('theming-log');

var colorDetectionOptions = {
// If on Windows, ignore the isTTY check
// This is due to AppVeyor (and thus probably common Windows platforms?) failing the check
// This is due to AppVeyor (and thus probably common Windows platforms?)
// failing the check
// TODO: If this is too broad, we can reduce it to an APPVEYOR env check
ignoreTTY: (process.platform === 'win32'),
};

// Needed to add this because node 10 decided to start coloring log output randomly
// Needed to add this because node 10 decided to start coloring log output
// randomly
var console;
/* istanbul ignore else */
if (nodeVersion.major >= 10) {
// Node 10 also changed the way this is constructed
console = new Console({
Expand Down Expand Up @@ -47,44 +51,59 @@ function addColor(str) {
}

function getTimestamp() {
return '[' + addColor(timestamp('HH:mm:ss')) + ']';
return themingLog.format(log.theme, '{TIMESTAMP.FORMAT}');
}

function log() {
var time = getTimestamp();
process.stdout.write(time + ' ');
process.stdout.write(time);
console.log.apply(console, arguments);
return this;
}

Object.defineProperty(log, 'theme', {
value: {
NOW: timestamp,
TIMESTAMP: {
COLOR: addColor,
FORMAT: '[{TIMESTAMP.COLOR: {NOW: HH:mm:ss}}] ',
},
},
});

function info() {
var time = getTimestamp();
process.stdout.write(time + ' ');
process.stdout.write(time);
console.info.apply(console, arguments);
return this;
}

function dir() {
var time = getTimestamp();
process.stdout.write(time + ' ');
process.stdout.write(time);
console.dir.apply(console, arguments);
return this;
}

function warn() {
var time = getTimestamp();
process.stderr.write(time + ' ');
process.stderr.write(time);
console.warn.apply(console, arguments);
return this;
}

function error() {
var time = getTimestamp();
process.stderr.write(time + ' ');
process.stderr.write(time);
console.error.apply(console, arguments);
return this;
}

log.themed = themingLog(log.theme, log, true);
info.themed = themingLog(log.theme, info, true);
warn.themed = themingLog(log.theme, warn, true);
error.themed = themingLog(log.theme, error, true);

module.exports = log;
module.exports.info = info;
module.exports.dir = dir;
Expand Down
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -28,9 +28,14 @@
"ansi-gray": "^0.1.1",
"color-support": "^1.1.3",
"parse-node-version": "^1.0.0",
"theming-log": "^2.1.1",
"time-stamp": "^1.0.0"
},
"devDependencies": {
"ansi-blue": "^0.1.1",
"ansi-green": "^0.1.1",
"ansi-red": "^0.1.1",
"ansi-yellow": "^0.1.1",
"eslint": "^2.13.0",
"eslint-config-gulp": "^3.0.1",
"expect": "^1.20.2",
Expand Down

0 comments on commit e8584af

Please sign in to comment.