Skip to content

Commit

Permalink
mode progress
Browse files Browse the repository at this point in the history
  • Loading branch information
dodekeract committed May 19, 2016
1 parent f657f96 commit e75fc19
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 40 deletions.
36 changes: 20 additions & 16 deletions build/console-logger.js
Expand Up @@ -3,6 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mode = undefined;

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

Expand All @@ -22,10 +23,14 @@ var ConsoleLogger = function () {
function ConsoleLogger(options) {
_classCallCheck(this, ConsoleLogger);

this.options = Object.assign({
muted: false
options = Object.assign({
muted: false,
mode: mode.smart
}, options);

this.mode = options.mode;
this.muted = options.muted;

if (options.instance) {
options.instance.on('log', this.log);
options.instance.on('separator', this.separator);
Expand All @@ -42,9 +47,9 @@ var ConsoleLogger = function () {
_createClass(ConsoleLogger, [{
key: 'log',
value: function log(id, level, messages) {
var string = level + ' ' + id + ' ' + messages;
var string = modes[this.mode][level] + ' ' + id + ' ' + messages;

if (!this.options.muted) console.log(string);
if (!this.muted) console.log(string);
return string;
}

Expand All @@ -57,9 +62,9 @@ var ConsoleLogger = function () {
}, {
key: 'separator',
value: function separator(id, level, messages) {
var string = level + ' ' + id + ' ' + messages;
var string = modes[this.mode][level] + ' ' + id + ' ' + messages;

if (!this.options.muted) console.log(string);
if (!this.muted) console.log(string);
return string;
}
}]);
Expand All @@ -70,14 +75,13 @@ var ConsoleLogger = function () {
exports.default = ConsoleLogger;


var modes = {
short: {},
smart: {},
full: {},
tiny: {},
shortNoBrackets: {},
smartNoBrackets: {},
fullNoBrackets: {},
numbers: {},
single: {}
var modes = [['DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'CRITICAL', 'ALERT', 'EMERGENCY', 'TIME'], ['EMER', 'ALER', 'CRIT', 'ERRO', 'WARN', 'NOTI', 'INFO', 'DEBU', 'TIME'], ['DBUG', 'INFO', 'NOTC', 'WRNG', 'RROR', 'CRTC', 'ALRT', 'MRGC', 'TIME'], ['EM', 'AL', 'CR', 'ER', 'WA', 'NO', 'IN', 'DE', 'TI'], ['1', '2', '3', '4', '5', '6', '7', '8', 'T'], ['M', 'A', 'C', 'R', 'W', 'N', 'I', 'D', 'T']];

var mode = exports.mode = {
full: 0,
short: 1,
smart: 2,
tiny: 3,
numbers: 4,
single: 5
};
42 changes: 26 additions & 16 deletions source/console-logger.js
Expand Up @@ -4,10 +4,14 @@ import moment from 'moment';
export default class ConsoleLogger {

constructor (options) {
this.options = Object.assign({
muted: false
options = Object.assign({
muted: false,
mode: mode.smart
}, options);

this.mode = options.mode;
this.muted = options.muted;

if (options.instance) {
options.instance.on('log', this.log);
options.instance.on('separator', this.separator);
Expand All @@ -20,9 +24,9 @@ export default class ConsoleLogger {
* @param messages
*/
log (id, level, messages) {
let string = `${level} ${id} ${messages}`;
let string = `${modes[this.mode][level]} ${id} ${messages}`;

if (!this.options.muted) console.log(string);
if (!this.muted) console.log(string);
return string;
}

Expand All @@ -32,22 +36,28 @@ export default class ConsoleLogger {
* @param messages
*/
separator (id, level, messages) {
let string = `${level} ${id} ${messages}`;
let string = `${modes[this.mode][level]} ${id} ${messages}`;

if (!this.options.muted) console.log(string);
if (!this.muted) console.log(string);
return string;
}

}

let modes = {
short: {},
smart: {},
full: {},
tiny: {},
shortNoBrackets: {},
smartNoBrackets: {},
fullNoBrackets: {},
numbers: {},
single: {}
let modes = [
['DEBUG','INFO','NOTICE','WARNING','ERROR','CRITICAL','ALERT','EMERGENCY','TIME'],
['EMER','ALER','CRIT','ERRO','WARN','NOTI','INFO','DEBU','TIME'],
['DBUG','INFO','NOTC','WRNG','RROR','CRTC','ALRT','MRGC','TIME'],
['EM','AL','CR','ER','WA','NO','IN','DE','TI'],
['1','2','3','4','5','6','7','8','T'],
['M','A','C','R','W','N','I','D','T']
];

export let mode = {
full: 0,
short: 1,
smart: 2,
tiny: 3,
numbers: 4,
single: 5
};
16 changes: 8 additions & 8 deletions test/console-logger.js
Expand Up @@ -24,63 +24,63 @@ describe('console-logger', () => {
expect(
logger.log(0, level.EMERGENCY, 'something something')
).to.be(
'7 0 something something'
'MRGC 0 something something'
);
});

it('alert', () => {
expect(
logger.log(0, level.ALERT, 'something something')
).to.be(
'6 0 something something'
'ALRT 0 something something'
);
});

it('critical', () => {
expect(
logger.log(0, level.CRITICAL, 'something something')
).to.be(
'5 0 something something'
'CRTC 0 something something'
);
});

it('error', () => {
expect(
logger.log(0, level.ERROR, 'something something')
).to.be(
'4 0 something something'
'RROR 0 something something'
);
});

it('warning', () => {
expect(
logger.log(0, level.WARNING, 'something something')
).to.be(
'3 0 something something'
'WRNG 0 something something'
);
});

it('notice', () => {
expect(
logger.log(0, level.NOTICE, 'something something')
).to.be(
'2 0 something something'
'NOTC 0 something something'
);
});

it('info', () => {
expect(
logger.log(0, level.INFO, 'something something')
).to.be(
'1 0 something something'
'INFO 0 something something'
);
});

it('debug', () => {
expect(
logger.log(0, level.DEBUG, 'something something')
).to.be(
'0 0 something something'
'DBUG 0 something something'
);
});

Expand Down

0 comments on commit e75fc19

Please sign in to comment.