From dc4edf775d0e817eb6a327021dde078966a1673f Mon Sep 17 00:00:00 2001 From: Tyler Long Date: Tue, 11 Apr 2017 23:46:11 +0800 Subject: [PATCH] Fix style issue of logger.js --- package.json | 4 +++- src/logger.js | 43 +++++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 9ba4be6d1..eb93c532e 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,9 @@ "ignore": [ "**/parser/*.js", "src/d3.js", - "dist/*.js" + "dist/**/*.js", + "docs/**/*.js", + "editor/**/*.js" ] }, "dependencies": { diff --git a/src/logger.js b/src/logger.js index 10196c6fe..11dbd9cfc 100644 --- a/src/logger.js +++ b/src/logger.js @@ -10,16 +10,16 @@ * => [2011-3-3T20:24:4.810 error (5021)] booom */ -const LEVELS = { - debug: 1, - info: 2, - warn: 3, - error: 4, - fatal: 5, - default: 5 -} +// const LEVELS = { +// debug: 1, +// info: 2, +// warn: 3, +// error: 4, +// fatal: 5, +// default: 5 +// } -var defaultLevel = LEVELS.error +// var defaultLevel = LEVELS.error // exports.setLogLevel = function (level) { // defaultLevel = level; @@ -73,17 +73,20 @@ var fatal = function () {} * * fatal: 5 */ exports.setLogLevel = function (level) { - switch (level) { - case 1: - exports.Log.debug = window.console.debug.bind(window.console, format('DEBUG', name), 'color:grey;', 'color: green;') - case 2: - exports.Log.info = window.console.debug.bind(window.console, format('INFO', name), 'color:grey;', 'color: info;') - case 3: - exports.Log.warn = window.console.debug.bind(window.console, format('INFO', name), 'color:grey;', 'color: orange;') - case 4: - exports.Log.error = window.console.debug.bind(window.console, format('ERROR', name), 'color:grey;', 'color: red;') - case 5: - exports.Log.fatal = window.console.debug.bind(window.console, format('FATAL', name), 'color:grey;', 'color: red;') + if (level < 6) { + exports.Log.fatal = window.console.debug.bind(window.console, format('FATAL'), 'color:grey;', 'color: red;') + } + if (level < 5) { + exports.Log.error = window.console.debug.bind(window.console, format('ERROR'), 'color:grey;', 'color: red;') + } + if (level < 4) { + exports.Log.warn = window.console.debug.bind(window.console, format('WARN'), 'color:grey;', 'color: orange;') + } + if (level < 3) { + exports.Log.info = window.console.debug.bind(window.console, format('INFO'), 'color:grey;', 'color: info;') + } + if (level < 2) { + exports.Log.debug = window.console.debug.bind(window.console, format('DEBUG'), 'color:grey;', 'color: green;') } }