This Gist was automatically created by Carbide, a free online programming environment.
Last active
September 18, 2016 21:12
-
-
Save z81/853b03354902df0004cfdd33a09ac113 to your computer and use it in GitHub Desktop.
logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const logs = new Map(); | |
| let tagFlag = 1; | |
| let log = { | |
| isEnabled() { | |
| return true; | |
| }, | |
| info(tags = [], text) { | |
| if (this.isEnabled()) { | |
| logs.set({ | |
| tags, | |
| text, | |
| level: 'info' | |
| }) | |
| } | |
| }, | |
| show(tags) { | |
| for(const [row] of logs) { | |
| let isShow = ( | |
| row.tags && tags | |
| ); | |
| if (isShow) { | |
| console[row.type](row.text); | |
| } | |
| } | |
| }, | |
| addTag(tagName = '') { | |
| if (typeof tagName !== 'string' || !tagName.length) return; | |
| this[tagName.toUpperCase()] = tagFlag; | |
| tagFlag *= 2; | |
| } | |
| } | |
| log.addTag('ELEMENT'); | |
| log.info('no tags'); | |
| log.info(log.ELEMENT, 'test tag'); | |
| log.show(log.ELEMENT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment