loggy
Colorful stdstream dead-simple logger for node.js.
- Logs stuff to stdout (
log
, info
, success
). - Logs errors & warnings to stderr (
warn
, error
). - Adds colors to log types (e.g.
warn
, info
words will be colored). Uses lightweight colorette. - Emits system notifications for errors with native-notifier.
- Tracks whether any error was logged (useful for changing process exit code).
- No 3rd-party deps (Growl etc.)
Install with npm install loggy
.
Usage
Example:
const logger = require('loggy');
logger.info('Hello', 'loggy');
logger.warn('Deprecated');
logger.error('Oops');
process.on('exit', () => {
process.exit(logger.errorHappened ? 1 : 0);
});
logger.colors = false;
logger.notifications = false;
logger.notifications = ['error', 'warn', 'success'];
logger.notificationsTitle = 'My App';
logger.dumpStacks = true;
Environment variables:
LOGGY_STACKS
: default value for dumpStacks
. Pass 1
to see the stacks.FORCE_NO_COLOR
: disables color output in chalk
. Does not affect logger.colors
.
Methods:
logger.error(...args)
- logs messages in red to stderr, creates notification.logger.warn(...args)
- logs messages in yellow to stdout.logger.log(...args)
- logs messages in cyan to stdout.logger.info
, logger.success
- logs messages in green to stdout.logger.format(level)
- function that does color and date formatting.
Params:
logger.colors
- mapping of log levels to colors.
Can be object, like {error: 'red', log: 'cyan'}
or false
(disables colors).logger.errorHappened
- false
, changes to true
if any error was logged.logger.notifications
- As Boolean, enables or disables notifications for errors, or
as Array, list types to trigger notifications, like ['error', 'warn', 'success']
.logger.notificationsTitle
- String, optional, prepends title in notifications.
License
MIT (c) 2016 Paul Miller (http://paulmillr.com)