Skip to content

Instantly share code, notes, and snippets.

@msikma
Created December 10, 2015 12:22
Show Gist options
  • Save msikma/358542b3fd034f888b6d to your computer and use it in GitHub Desktop.
Save msikma/358542b3fd034f888b6d to your computer and use it in GitHub Desktop.
/**
* Returns a function that will print a line to the console in a given color.
* The line will be prefixed and colored. All substituted values are bolded.
*
* @param {String} color Color to print in (must be supported by cli-color)
* @param {String} level Severity of the message {log, info, warn, error}
* @param {String} pre Prefix character in front of the message
* @returns {Function} Logging printer
*/
function logMessage(color, level='log', pre=bullet) {
return function(msg, ...subs) {
subs = subs.map(sub => clc.bold(sub));
console[level].apply(console, [clc[color](`${pre} ${msg}`)].concat(subs));
}
}
/**
* Prints a line of text to the console indicating success.
*
* @param {String} msg Message to log to the console
* @param {Array} subs Any desired substitution values
*/
const logSuccess = logMessage('green', 'log');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment