hallo-logger
v1.1.0
Published
Say hello to your messages in your console!
Downloads
16
Maintainers
Readme
About 📘
Introducing HalloLogger, a straightforward yet powerful logger designed to bring clarity to your console output. With this logger, you can effortessly create organized and structued logs, making it easier than ever to track and understand your application's behavior. Say goodby to cluttered console screens 👋.
Installation 📦
# With npm
npm install hallo-logger
# With yarn
yarn add hallo-logger
Usage 🚀
Basic debug messages
This package includes several debug messages that provide insights and create a clear picture of your application's behavior. You can add to these messages a prefix with the prefix
option. This will help you identify the source of the message.
const HalloLogger = require('hallo-logger');
const logger = new HalloLogger({ prefix: 'Main' });
logger.ready('Application is ready to serve requests.');
logger.info('Server is listening on port 3000.');
logger.warn('Server is running in development mode.');
logger.error('Failed to connect to database.');
By default, the logger will output a message into the console with only the time of the message. However, you can also add the current date to the message by setting the withDate
option to true
when initializing the logger.
const logger = new HalloLogger({ prefix: 'Main', withDate: true });
Ready message
The logger class does also have a static appReady
method that can be used to log a ready message. This message will display some important information from the package.json
file, such as the application's name and version. You can also add custom information properties to this message.
const HalloLogger = require('hallo-logger');
const express = require('express');
// Get the application's start time
const startMs = Date.now();
// Express app
const app = express();
app.listen(8080);
// Ready message
HalloLogger.appReady(startMs, {
'🚪 Port': ':8080',
'🌳 Environment': 'development'
});
Note: For this example I used an example with a ExpressJS app. However, this method can be used with any type of application.
License 📜
This proejct is licensed under the MIT License - see the LICENSE file for details.