Skip to content

Instantly share code, notes, and snippets.

@gvn
Last active January 4, 2016 09:58
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 gvn/8605287 to your computer and use it in GitHub Desktop.
Save gvn/8605287 to your computer and use it in GitHub Desktop.
Echo (Proof of concept)
window.echo = function (message, namespace) {
if (namespace && !echo.namespaces[namespace]) {
return;
}
console.log(message);
};
// TODO : DRY
echo.warn = function (message, namespace) {
if (namespace && !echo.namespaces[namespace]) {
return;
}
console.warn(message);
};
// TODO : DRY
echo.error = function (message, namespace) {
if (namespace && !echo.namespaces[namespace]) {
return;
}
console.error(message);
};
// Configure what namespaces you want turned on
echo.namespaces = {
contact: true,
carousel: false
};
// This will display because the 'contact' namespace is enabled:
echo.warn('Invalid email', 'contact');
// This will not show up because carousel logs are turned off
echo('Slide changed', 'carousel');
// This will not show up because the namespace is undefined
// In production you can simply omit the `echo.namespaces` property to silence logs
echo('Oh hai', 'kitten');
// Namespace-free logs will always show up:
echo('Generic message');
@gvn
Copy link
Author

gvn commented Jan 24, 2014

Typical usage would involve creating a namespace for each component that you want logging for. This way most components can be silenced while you're working on a specific one.

@gvn
Copy link
Author

gvn commented Jan 24, 2014

Further functionality might include a config option to pipe logs to a web service. A use case would be logging all error messages that users encounter on production.

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