diff --git a/build/console-logger.js b/build/console-logger.js index 054abf4..99259f5 100644 --- a/build/console-logger.js +++ b/build/console-logger.js @@ -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; }; }(); @@ -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); @@ -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; } @@ -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; } }]); @@ -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 }; \ No newline at end of file diff --git a/source/console-logger.js b/source/console-logger.js index fa19f60..c28e61f 100644 --- a/source/console-logger.js +++ b/source/console-logger.js @@ -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); @@ -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; } @@ -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 }; diff --git a/test/console-logger.js b/test/console-logger.js index 4075720..008d702 100644 --- a/test/console-logger.js +++ b/test/console-logger.js @@ -24,7 +24,7 @@ describe('console-logger', () => { expect( logger.log(0, level.EMERGENCY, 'something something') ).to.be( - '7 0 something something' + 'MRGC 0 something something' ); }); @@ -32,7 +32,7 @@ describe('console-logger', () => { expect( logger.log(0, level.ALERT, 'something something') ).to.be( - '6 0 something something' + 'ALRT 0 something something' ); }); @@ -40,7 +40,7 @@ describe('console-logger', () => { expect( logger.log(0, level.CRITICAL, 'something something') ).to.be( - '5 0 something something' + 'CRTC 0 something something' ); }); @@ -48,7 +48,7 @@ describe('console-logger', () => { expect( logger.log(0, level.ERROR, 'something something') ).to.be( - '4 0 something something' + 'RROR 0 something something' ); }); @@ -56,7 +56,7 @@ describe('console-logger', () => { expect( logger.log(0, level.WARNING, 'something something') ).to.be( - '3 0 something something' + 'WRNG 0 something something' ); }); @@ -64,7 +64,7 @@ describe('console-logger', () => { expect( logger.log(0, level.NOTICE, 'something something') ).to.be( - '2 0 something something' + 'NOTC 0 something something' ); }); @@ -72,7 +72,7 @@ describe('console-logger', () => { expect( logger.log(0, level.INFO, 'something something') ).to.be( - '1 0 something something' + 'INFO 0 something something' ); }); @@ -80,7 +80,7 @@ describe('console-logger', () => { expect( logger.log(0, level.DEBUG, 'something something') ).to.be( - '0 0 something something' + 'DBUG 0 something something' ); });