Last active
February 1, 2017 12:43
-
-
Save jmjpro/7e39c7c60e2eb8e4d0bd381e831345b8 to your computer and use it in GitHub Desktop.
wrap all console log methods with a specified prefix
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
// 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