Note that this project is still in preview stage
Master | Develop |
---|---|
Log utility used in NodeJS environment.
- Featuring parsing objects using
util.inspect
and coloured outputs; - Supporting NodeJS 6 and above.
The currently supported log levels are
Level | Description |
---|---|
MUTE | Avoid all outputs |
INFO | Informational outputs |
LOG | Generic logging, when enabled, the outputs of INFO will also be printed. |
WARN | Warning, when enabled, the outputs of INFO and LOG will also be printed. |
ERROR | Errors, when enabled, the outputs of INFO, LOG and WARN will also be printed |
DEBUG | Debugging information, when enabled, the outputs of INFO, LOG, WARN and ERROR will also be printed |
VERBOSE | Anything, including the outputs of all of the other logging levels. |
Set LOG_${levelName}
environment variable to true
to enable the given level, i.e. LOG_DEBUG=true
;
Basic unit test powered by Mocha/Chai/Sinon;
Table of Contents
# command format
npm install --save github:unknownmoon/utility-node-log#<version>
# example
npm i -S github:unknownmoon/utility-node-log#v0.0.4
Detailed APIs please reference to the JSDoc. Generate JSDoc Documentation
import {logger} from 'utility-node-log';
// if muted
logger.logLevel = 'MUTE';
logger.log('anything'); // no outputs
// if error
logger.logLevel = 'ERROR';
logger.log('anything'); // [<time>][LOG] anything
logger.error('anything'); // [<time>][ERROR] anything
logger.debug('anything'); // no outputs
import {logger} from 'utility-node-log';
// will be used to feed `moment.format`
logger.timeFormat = 'HH.mm.ss.SS';
import {logger} from 'utility-node-log';
// used `chalk` colour functions to do the job
const result = logger.highlight('something');
// result: '<color-code>something<color-code>'
The currently supported colour cases are:
highlight
time
info
warn
error
debug
- also used inlog
andverbose
cases.help
- not in use
import {logger} from 'utility-node-log';
import chalk from 'chalk';
// only the given functions will be overridden
logger.colorMapping = new Map([
['highlight', chalk.cyan],
['time', chalk.gray]
]);
import {logger} from 'utility-node-log';
// similar to use `console.log`, but with `[<time>][<log level>]` wrapper and coloured.
logger.info('anything'); // [<time>][INFO] anything
logger.log('anything'); // [<time>][LOG] anything
logger.warn('anything'); // [<time>][WARN] anything
logger.error('anything'); // [<time>][ERROR] anything
logger.debug('anything'); // [<time>][DEBUG] anything
logger.verbose('anything'); // [<time>][VERBOSE] anything
// -------
logger.inspect({ a: 1 });
// is the shorthand of
logger.debug( require( 'util' )
.inspect( { a: 1 }, { depth: 7, colors: true } ) );
# Have Node ^6.0.0 & NPM ^3.8.6 installed
# install dependencies
npm install
# remove the built code, for now only the test result
npm run clean
# remove the built code and node modules
npm run reset
Coverage report can be found in ./coverage
folder.
npm test
The source code is written in ES2015, hence before NodeJS fully support ES2015, we need to build the code to es2015-node
using [Babel][babel-link].
The built code can be found in ./dist
folder.
npm run build
# generate the documentation
npm run doc
# serve the generated documentation using `http-server`
# note that no watch functionality is hooked, hence
# changing code won't trigger documentation regeneration.
npm run serve-doc
Shorthand script to generate release content, including ./coverage
, ./jsdoc
and ./dist
.
npm run release