Skip to content

psfe/oh-my-console

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Oh My Console

NPM version Build Status Coverage Status Dependency manager

Shell:

shell

Browser:

browser

Installation

Node.js

npm install oh-my-console

Browser

<script>window.DEBUG="main"</script>
<script src="dist/oh-my-console.min.js"></script>

Usage

Node.js

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.

AMD

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.

Global Object for Browser

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.

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"}.

About

A JavaScript Logger for Node.js and Browsers

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published