A small, flexible logger for Node.js
Usage is pretty basic:
var logging = require('femto-logging'); logging.info('Something happened.');
which will yield something like:
2014-02-18T23:34:12+00:00 [INFO] Something happened.
Femto-logger uses ANSI coloring to color the log line according to the level.
The colors can be altered to your liking as such:
logging.config.colors.debug = logging.BRIGHT_CYAN;
The defaults are as follows:
Possible values are: DARK_BLACK, DARK_RED, DARK_GREEN, DARK_YELLOW, DARK_BLUE, DARK_MAGENTA, DARK_CYAN, DARK_WHITE, BRIGHT_BLACK, BRIGHT_RED, BRIGHT_GREEN, BRIGHT_YELLOW, BRIGHT_BLUE, BRIGHT_MAGENTA, BRIGHT_CYAN, BRIGHT_WHITE, and NONE
It can also be disabled, which is equivalent to setting all colors to NONE:
logging.config.coloring = false;
Timestaamps default to UTC (GMT) for consistency, though the exact time is still based on the system clock and not an external time source. The default format is ISO 8601.
The format can be changed as such:
logging.config.date.format = 'YYYY-MM-DDTHH:mm:ssZ';
There is currently a single constant ISO8601 that can be used to reset the value.
Level labels can also be altered as such:
logging.config.labels.debug = 'DEBUG';
Messages can be formatted using printf-style placeholders:
logging.debug('These are placeholders: %s, %d', 'abc', 789);
More information on usage of placeholders is available at the node-printf project website.
In addition to messages being logged to the console, they are also returned from the logging function:
var message = logging.debug('Now the message variable has this content as well.');
Messages are logged to the console by default, but can be turned off easily:
logging.config.console.suppress = true;