omc
v1.0.1
Published
A JavaScript Logger for Node.js and Browsers
Downloads
2
Readme
Oh My Console
Shell:
Browser:
Installation
Node.js
npm install omc
Browser
<script>window.DEBUG="main"</script>
<script src="dist/omc.min.js"></script>
Usage
Node.js
var logger = require('omc')('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.
AMD
dist/omc 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.
Global Object for Browser
dist/omc 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.
API
logger.debug
debug output respect to process.env.DEBUG
or window.DEBUG
.
logger.info
info level output implemented by console.info
.
logger.log
log level output implemented by console.log
.
logger.warn
warn level output implemented by console.warn
.
logger.error
error level output implemented by console.error
.
Format
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"}.