1.0.8 • Published 5 years ago
loggy v1.0.8
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');
// "05:48:30 - log: Hello, loggy" to stdout.
// "info" word is cyan.
logger.info('Hello', 'loggy');
// "05:48:30 - warn: Deprecated" to stderr.
// "warn" word is yellow.
logger.warn('Deprecated');
// Logs "05:48:30 - error: Oops" to stderr.
// "error" word is red.
// Emits system notifications with title "Error" and message "Oops”.
logger.error('Oops');
// Exit with proper code.
process.on('exit', () => {
process.exit(logger.errorHappened ? 1 : 0);
});
// Disable colors.
logger.colors = false;
// Disable system notifications.
logger.notifications = false;
// Enable notifications for more methods
logger.notifications = ['error', 'warn', 'success'];
// Prepend the notifications title
logger.notificationsTitle = 'My App';
// Dump stacks of Error objects in errors or warnings
logger.dumpStacks = true; // or color of your choice
Environment variables:
LOGGY_STACKS
: default value fordumpStacks
. Pass1
to see the stacks.FORCE_NO_COLOR
: disables color output inchalk
. Does not affectlogger.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'}
orfalse
(disables colors).logger.errorHappened
-false
, changes totrue
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)
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago
0.3.5
8 years ago
0.3.4
8 years ago
0.3.3
8 years ago
0.3.2
8 years ago
0.3.1
8 years ago
0.3.0
8 years ago
0.2.2
9 years ago
0.2.1
9 years ago
0.2.0
11 years ago
0.1.0
11 years ago