Last active
November 24, 2020 21:35
-
-
Save vitriolix/b0da1a305b5280e5152fd52b1edc6d3a to your computer and use it in GitHub Desktop.
A time stamped log function with an allow list, block list and solo list that filters log messages based on an optional tag param. Future: optional color, optional spacing, solo list
This file contains 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
export var blockList = [] | |
export var allowList = [] | |
// export var soloList = ['foo'] | |
// TODO | |
// - prepend the name of the arguments that it is printing out? | |
// - optional color | |
// - optional spacing | |
// - solo list | |
export default function log(msg, tag=null){ | |
let d = new Date() | |
let mo = (d.getMonth() < 10 ? '0' : '') + d.getMonth() + 1 | |
let da = (d.getDate() < 10 ? '0' : '') + d.getDate() | |
let ho = (d.getHours() < 10 ? '0' : '') + d.getHours() | |
let mi = (d.getMinutes() < 10 ? '0' : '') + d.getMinutes() | |
let se = (d.getMinutes() < 10 ? '0' : '') + d.getMinutes() | |
let ms = (((d.getMilliseconds() < 100) ? '0' : '') + ((d.getMilliseconds() < 10) ? '0' : '') + d.getMilliseconds()) | |
let LOG_PREFIX = '\x1b[32m' + d.getFullYear() + '.' + mo + '.' + da + '-' + ho + ':' + mi + ':' + se + ':' + ms + '\x1b[0m\n '; | |
// 1. Convert args to a normal array | |
// var args = Array.prototype.slice.call(arguments); | |
// 2. Prepend log prefix log string | |
// args.unshift(LOG_PREFIX + " "); | |
if (allowList.includes(tag) || !(blockList.includes('*') || blockList.includes(tag))) { | |
let message = LOG_PREFIX + msg + '\x1b[0m'; | |
console.log(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment