Productivity
A lightweight and colorful logging package for Node.js and Bun applications. Makes your console output beautiful and saves logs to files!
# Using npm
npm install pretty-js-log
# Using bun
bun install pretty-js-log
const { logFactory } = require('pretty-js-log');
// Create a basic logger
const logger = logFactory({});
// Log some messages
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');
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!');
const data = {
user: 'john',
age: 25
};
logger('User data:', data); // Objects are automatically formatted
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 file
});
logger('This will only appear in the log file');
logger.info('Silent logging to file');
When you run your logs, they'll look something like this in the console:
[2024-03-15 10:30:45] - [id:1234] - Hello World
[2024-03-15 10:30:46] - [id:1234] - This is an info message
[2024-03-15 10:30:47] - [id:1234] - Warning! Something needs attention
Feel free to open issues and submit PRs! This is an open-source project and we welcome contributions.
MIT License - feel free to use this in your projects!
Belguinan Noureddine
GitHub: https://github.com/belguinan