Skip to content

Commit

Permalink
Separate routing matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkGriffiths committed Feb 15, 2019
1 parent 01695ee commit d696fc2
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 188 deletions.
90 changes: 47 additions & 43 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,58 @@ Object.defineProperty(exports, '__esModule', { value: true });

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var chalk = _interopDefault(require('chalk'));
var util = _interopDefault(require('util'));
var termNG = _interopDefault(require('term-ng'));
var chalk = _interopDefault(require('chalk'));
var sparkles = _interopDefault(require('sparkles'));
var time = require('@thebespokepixel/time');
var meta = _interopDefault(require('@thebespokepixel/meta'));

function matrix(sOut, sErr) {
return {
debug: {
level: 5,
stream: sOut,
format: (pfix, msg) => `${pfix}${chalk.dim(msg)}`
},
info: {
level: 4,
stream: sOut,
format: (pfix, msg) => `${pfix}${msg}`
},
log: {
level: 3,
stream: sOut,
format: (pfix, msg) => `${pfix}${msg}`
},
warn: {
level: 2,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.yellow(msg)}`
},
error: {
level: 1,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.red(`ERROR: ${msg}`)}`
},
critical: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`CRITICAL: ${msg}`)}`
},
panic: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`PANIC: ${msg}`)}`
},
emergency: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`EMERGENCY: ${msg}`)}`
}
};
}

const {
format,
inspect
Expand Down Expand Up @@ -54,48 +99,7 @@ class Verbosity extends Console {
this._stderr = sErr;
this.threshold = verbosity ? verbosity : 3;
this.emitter = this.willEmit && sparkles(namespace);
this.matrix = {
debug: {
level: 5,
stream: sOut,
format: (pfix, msg) => `${pfix}${chalk.dim(msg)}`
},
info: {
level: 4,
stream: sOut,
format: (pfix, msg) => `${pfix}${msg}`
},
log: {
level: 3,
stream: sOut,
format: (pfix, msg) => `${pfix}${msg}`
},
warn: {
level: 2,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.yellow(msg)}`
},
error: {
level: 1,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.red(`ERROR: ${msg}`)}`
},
critical: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`CRITICAL: ${msg}`)}`
},
panic: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`PANIC: ${msg}`)}`
},
emergency: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`EMERGENCY: ${msg}`)}`
}
};
this.matrix = matrix(sOut, sErr);
}

verbosity(level) {
Expand Down
90 changes: 47 additions & 43 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,55 @@
import chalk from 'chalk';
import util from 'util';
import termNG from 'term-ng';
import chalk from 'chalk';
import sparkles from 'sparkles';
import { bespokeTimeFormat } from '@thebespokepixel/time';
import meta from '@thebespokepixel/meta';

function matrix(sOut, sErr) {
return {
debug: {
level: 5,
stream: sOut,
format: (pfix, msg) => `${pfix}${chalk.dim(msg)}`
},
info: {
level: 4,
stream: sOut,
format: (pfix, msg) => `${pfix}${msg}`
},
log: {
level: 3,
stream: sOut,
format: (pfix, msg) => `${pfix}${msg}`
},
warn: {
level: 2,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.yellow(msg)}`
},
error: {
level: 1,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.red(`ERROR: ${msg}`)}`
},
critical: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`CRITICAL: ${msg}`)}`
},
panic: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`PANIC: ${msg}`)}`
},
emergency: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`EMERGENCY: ${msg}`)}`
}
};
}

const {
format,
inspect
Expand Down Expand Up @@ -48,48 +93,7 @@ class Verbosity extends Console {
this._stderr = sErr;
this.threshold = verbosity ? verbosity : 3;
this.emitter = this.willEmit && sparkles(namespace);
this.matrix = {
debug: {
level: 5,
stream: sOut,
format: (pfix, msg) => `${pfix}${chalk.dim(msg)}`
},
info: {
level: 4,
stream: sOut,
format: (pfix, msg) => `${pfix}${msg}`
},
log: {
level: 3,
stream: sOut,
format: (pfix, msg) => `${pfix}${msg}`
},
warn: {
level: 2,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.yellow(msg)}`
},
error: {
level: 1,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.red(`ERROR: ${msg}`)}`
},
critical: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`CRITICAL: ${msg}`)}`
},
panic: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`PANIC: ${msg}`)}`
},
emergency: {
level: 0,
stream: sErr,
format: (pfix, msg) => `${pfix}${chalk.bold.red(`EMERGENCY: ${msg}`)}`
}
};
this.matrix = matrix(sOut, sErr);
}

verbosity(level) {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"acorn": "^6.1.0",
"ava": "^1.2.1",
"documentation": "^9.1.1",
"documentation-theme-bespoke": "^0.4.9",
"documentation-theme-bespoke": "^0.4.10",
"gulp": "^4.0.0",
"gulp-better-rollup": "^3.4.0",
"gulp-rename": "^1.4.0",
Expand Down
102 changes: 102 additions & 0 deletions src/lib/matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import chalk from 'chalk'

export default function matrix(sOut, sErr) {
return {
debug: {
level: 5,
stream: sOut,
/**
* Format the debug message.
* @private
* @param {String} pfix Message prefix.
* @param {String} msg The message body.
* @return {Sring} The formatted mesage.
*/
format: (pfix, msg) => `${pfix}${chalk.dim(msg)}`
},
info: {
level: 4,
stream: sOut,
/**
* Format the info message.
* @private
* @param {String} pfix Message prefix.
* @param {String} msg The message body.
* @return {Sring} The formatted mesage.
*/
format: (pfix, msg) => `${pfix}${msg}`
},
log: {
level: 3,
stream: sOut,
/**
* Format the log message.
* @private
* @param {String} pfix Message prefix.
* @param {String} msg The message body.
* @return {Sring} The formatted mesage.
*/
format: (pfix, msg) => `${pfix}${msg}`
},
warn: {
level: 2,
stream: sErr,
/**
* Format the warn message.
* @private
* @param {String} pfix Message prefix.
* @param {String} msg The message body.
* @return {Sring} The formatted mesage.
*/
format: (pfix, msg) => `${pfix}${chalk.yellow(msg)}`
},
error: {
level: 1,
stream: sErr,
/**
* Format the error message.
* @private
* @param {String} pfix Message prefix.
* @param {String} msg The message body.
* @return {Sring} The formatted mesage.
*/
format: (pfix, msg) => `${pfix}${chalk.red(`ERROR: ${msg}`)}`
},
critical: {
level: 0,
stream: sErr,
/**
* Format the critical message.
* @private
* @param {String} pfix Message prefix.
* @param {String} msg The message body.
* @return {Sring} The formatted mesage.
*/
format: (pfix, msg) => `${pfix}${chalk.bold.red(`CRITICAL: ${msg}`)}`
},
panic: {
level: 0,
stream: sErr,
/**
* Format the panic message.
* @private
* @param {String} pfix Message prefix.
* @param {String} msg The message body.
* @return {Sring} The formatted mesage.
*/
format: (pfix, msg) => `${pfix}${chalk.bold.red(`PANIC: ${msg}`)}`
},
emergency: {
level: 0,
stream: sErr,
/**
* Format the emergency message.
* @private
* @param {String} pfix Message prefix.
* @param {String} msg The message body.
* @return {Sring} The formatted mesage.
*/
format: (pfix, msg) => `${pfix}${chalk.bold.red(`EMERGENCY: ${msg}`)}`
}
}
}
Loading

0 comments on commit d696fc2

Please sign in to comment.