Shell:
Browser:
npm install oh-my-console
<script>window.DEBUG="main"</script>
<script src="dist/oh-my-console.min.js"></script>
var logger = require('oh-my-console')('main:foo');
logger.log('bar');
// Output:
// [<timestamp>][main:foo] bar
logger.debug('bar')
// Output only when DEBUG equals "main" or "main:foo"
// [<timestamp>][main:foo] bar
A demo can be found here.
dist/oh-my-console supports AMD envirenment, as long as loaded into your HTML:
window.DEBUG = "main";
require(['OhMyConsole'], function(Logger) {
var logger = Logger('main:sub');
logger.log('some information');
logger.error('there was an error');
logger.debug('matches DEBUG: main, main:sub');
});
A demo can be found here.
dist/oh-my-console will export a
window.OhMyConsole
object if there's no require
or module
defined.
window.DEBUG = "main";
var logger = window.OhMyConsole('main:sub');
logger.log('some information');
logger.error('there was an error');
logger.debug('matches DEBUG: main, main:sub');
A demo can be found here.
debug output respect to process.env.DEBUG
or window.DEBUG
.
info level output implemented by console.info
.
log level output implemented by console.log
.
warn level output implemented by console.warn
.
error level output implemented by console.error
.
format string supports:
"%s"
: string output"%d"
: number output"%j"
: json output"%J"
: prettified json output"%%"
: escaped%
For example:
logger.log('this logger is authored by %j.', { name: 'harttle' });
// Output:
// this logger is authored by {"name":"harttle"}.