Ever wished your Node.js console logs were more visually appealing and easier to parse? Meet pretty-js-log
, a lightweight logging package that brings color and structure to your console output while also supporting file logging!
β¨ Key Features
- π¨ Colorful console output with different colors for different log levels
- π Built-in file logging support
- β‘ Works with both Node.js and Bun
- π Timezone-aware timestamps
- π Process ID tracking
- π― JSON/Array pretty formatting
π Quick Start
Install with npm:
npm install pretty-js-log
Or with Bun:
bun install pretty-js-log
Basic usage:
const { logFactory } = require('pretty-js-log');
// Create a basic logger
const logger = logFactory({});
// Start logging!
logger('Hello World');
logger.info('This is an info message');
logger.warn('Warning! Something needs attention');
logger.error('Oops! Something went wrong');
logger.debug('Debug information');
π§ Advanced Usage
Save Logs to File
const logger = logFactory({
path: './logs/app.log', // Logs will be saved here
id: process.pid // Add process ID to logs
});
logger('This will be saved to the file too!');
Logging Objects
const data = {
user: 'john',
age: 25
};
logger('User data:', data); // Objects are automatically formatted
Disable Console Output
If you want to write logs only to file without console output, use the toStdout option:
const logger = logFactory({
path: './logs/app.log',
toStdout: false // Logs will only be written to the file only
});
logger('This will only appear in the log file');
logger.info('Silent logging to file');
π€ Why Another Logging Package?
- Simplicity: Just import and use - no complex configuration needed
- Lightweight: Minimal dependencies, perfect for small to medium projects
- Visual Appeal: Makes debugging more pleasant with color-coded log levels
- File Support: Built-in file logging without extra dependencies
- Modern: Works with both Node.js and Bun
π Links
π€ Contributing
This is an open-source project and we welcome contributions! Feel free to:
- Open issues
- Submit PRs
- Suggest features
- Help with documentation
π Future Plans
- File size-based rotation
- External logging API endpoints support
Give it a try and let me know what you think in the comments below!
Thanks!
Top comments (0)