This library provides to your app a set of pretty and colorful log formats with different importance levels (debug, info, warn, error, and fatal). It even gives you the opportunity to use markdown in your logs.
npm install beautify-logs
yarn add beautify-logs
pnpm add beautify-logs
const { Logger } = require('beautify-logs');
Instantiate the imported class with your own options (check their description further below)
const logger = new Logger({ ... });
logger.debug('Lorem Ipsum dolor sit amet.');
logger.info('Lorem Ipsum dolor sit amet.');
logger.warn('Lorem Ipsum dolor sit amet.');
logger.error('Lorem Ipsum dolor sit amet.');
logger.fatal('Lorem Ipsum dolor sit amet.');
To do so, simply assign the logger property to the process
in your index file.
Object.assign(process, {
logger: logger
});
process.logger.debug('The logger is now usable from anywhere!');
You can personalize your logger by providing your own options.
You can choose one of the many available formats (check further below). Default value is: 0
const logger = new Logger({
format: 3
});
logger.debug('This is the third format!');
You can provide as many messages as you want at once in a single log. This option allows you to wether split those or not. Default value is: false
const logger = new Logger({
splitMessages: true
});
logger.debug('Hello, World!', 'How is your day going?');
const logger = new Logger({
splitMessages: false
});
logger.debug('Hello, World!', 'How is your day going?');
You can choose to wether format the messages with some Markdown (bold, italic, underline, and URL coloring) or not. Default value is: true
const logger = new Logger({
formatMessages: true
});
logger.debug('Here is some **bold**, *italic*, __underline__, and https://example.com/');
const logger = new Logger({
formatMessages: false
});
logger.debug('Here is some **bold**, *italic*, __underline__, and https://example.com/');
- Note: The colors may slightly vary according to your terminal colors.
- More formats will come soon!
If an object is given as a message instead of a string, the library will display its whole content using util.inspect(...)
method.
const user = {
fullName: 'John Doe',
birthDate: new Date(1989, 8, 22),
hobbies: [
'programming',
'sport'
],
familyMembers: {
parents: {
mother: 'Coralie Clark',
father: 'William Doe'
}
}
};
logger.info('A user was created:', user);