Skip to content

Instantly share code, notes, and snippets.

@jmjpro
Last active February 1, 2017 12:43
Show Gist options
  • Save jmjpro/7e39c7c60e2eb8e4d0bd381e831345b8 to your computer and use it in GitHub Desktop.
Save jmjpro/7e39c7c60e2eb8e4d0bd381e831345b8 to your computer and use it in GitHub Desktop.
wrap all console log methods with a specified prefix
// Note: relies on es6 for..of loop and ..., the 'spread' operator; can easily be adapted to es5
function pconsole(prefix /* string */) {
// preserves original line number of calling function
// usage:
// const todo_console = pconsole('TODO');
// todo_console.log(1, 2) outputs 'TODO 1 2' and similar for debug, info, warn, etc... methods
const prefix_console = {};
const log_methods = ['debug', 'dir', 'error', 'exception', 'info', 'log', 'table', 'trace', 'warn'];
for (let method of log_methods) {
prefix_console[method] = window.console[method].bind(window.console, prefix);
}
return prefix_console;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment