Last active
March 23, 2019 12:04
-
-
Save adamcjoiner/64527c7b10297250b5234dd433d9479b to your computer and use it in GitHub Desktop.
Adds on/off capability and custom message coloring to console logs.
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
/* | |
Module Name: LogJS | |
Description: Adds on/off and custom coloring functions to console logs | |
Author: Adam C. Joiner | |
Author URI: http://www.adamcjoiner.com/ | |
Usage: log.on(); // off by default | |
log.post('message') // log to console in white text | |
log.debug('email sent successfully'); // gray text | |
log.info('sending email'); // yellow text | |
log.warning('server responded with no data'); | |
log.error('failed to send email'); // red text | |
*/ | |
var log = { | |
show: false, | |
color: "white", | |
info: function(string) { | |
log.color = "yellow"; | |
log.queue(string, log.color); | |
}, | |
debug: function(string) { | |
log.color = "gray"; | |
log.queue(string, log.color); | |
}, | |
error: function(string) { | |
log.color = "red"; | |
log.queue(string, log.color); | |
}, | |
on: function() { | |
log.show = true; | |
}, | |
off: function() { | |
log.show = false; | |
}, | |
queue: function(message, color) { | |
if(log.show === true) { | |
console.log(message, color); | |
} | |
} | |
} | |
/* | |
TODO: Add color for critical() | |
TODO: Turn individual colors on/off | |
TODO: Save log history in LocalStorage (i.e. log.history.save()) | |
TODO: log history to console (i.e. log.history.showLast( [line quantity, num] );) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment