Skip to content

Instantly share code, notes, and snippets.

@danielstgt
Last active October 29, 2021 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielstgt/295af7405d1236bb18ebf874c4c1ebcc to your computer and use it in GitHub Desktop.
Save danielstgt/295af7405d1236bb18ebf874c4c1ebcc to your computer and use it in GitHub Desktop.
Create a debug only alias for console.log
MIX_JS_DEBUG="${APP_DEBUG}"
['log', 'debug', 'warn', 'info', 'error', 'table', 'group', 'clear', 'count'].forEach(alias => {
if (typeof window[alias] === 'function') return;
window[alias] = process.env.MIX_JS_DEBUG === 'true'
? console[alias].bind(window.console)
: function () {};
});
@danielstgt
Copy link
Author

Description

Alias for console.log with output only in debug mode (Laravel Mix based).

Usage

log('this is an aliased console.log example');
error('whoops');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment