From 0c68c515dfb4a871c70b02c298eb3709984b2c2a Mon Sep 17 00:00:00 2001 From: Phantas Weng Date: Mon, 2 Dec 2019 17:25:08 +0800 Subject: [PATCH] Add Dark Mode option into logger --- src/index.js | 4 +++- src/logger.js | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index cea8ef0..a066cb9 100644 --- a/src/index.js +++ b/src/index.js @@ -11,11 +11,13 @@ export default class VueSocketIO { * @param io * @param vuex * @param debug + * @param darkMode * @param options */ - constructor({connection, vuex, debug, options}){ + constructor({connection, vuex, debug, darkMode, options}){ Logger.debug = debug; + Logger.darkMode = darkMode; this.io = this.connect(connection, options); this.useConnectionNamespace = (options && options.useConnectionNamespace); this.namespaceName = (options && options.namespaceName); diff --git a/src/logger.js b/src/logger.js index 950f4b0..70dd705 100644 --- a/src/logger.js +++ b/src/logger.js @@ -4,13 +4,20 @@ export default new class VueSocketIOLogger { constructor() { + this.darkMode = false; this.debug = false; this.prefix = '%cVue-Socket.io: '; } info(text, data = '') { - if(this.debug) window.console.info(this.prefix+`%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data); + if(this.debug) { + if (this.darkMode) { + window.console.info(this.prefix+`%c${text}`, 'color: #A9D341; font-weight: 600', 'color: #F7AC15', data); + } else { + window.console.info(this.prefix+`%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data); + } + } } @@ -28,7 +35,13 @@ export default new class VueSocketIOLogger { event(text, data = ''){ - if(this.debug) window.console.info(this.prefix+`%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data); + if(this.debug) { + if (this.darkMode) { + window.console.info(this.prefix+`%c${text}`, 'color: #A9D341; font-weight: 600', 'color: #F7AC15', data); + } else { + window.console.info(this.prefix+`%c${text}`, 'color: blue; font-weight: 600', 'color: #333333', data); + } + } }