Every robust logging system consists of three key components: a Collector, a Storage, and a Visualizer. Popular Node.js logging modules like Winston and Pino function solely as log collectors. Errsole, however, offers a complete logging solution that includes:
Log Storage: Save logs in a file or your application’s database.
Built-in Dashboard: View, filter, and search logs using the built-in dashboard.
Alerts: Receive real-time notifications for critical errors.
Installing Errsole and its dependencies
To use Errsole, you need to install the Errsole module along with a storage module based on your chosen database. Here are the installation steps for different storage options:
File Storage:
npm install errsole errsole-sqlite
MongoDB:
npm install errsole errsole-mongodb
MySQL:
npm install errsole errsole-mysql
PostgreSQL:
npm install errsole errsole-postgres
Creating a Custom Logger File
In a real-life Node.js project, you will have multiple files. To use the Errsole Logger in every file of your project, create a logger.js
file and initialize Errsole in it:
const errsole = require('errsole');
const ErrsoleSQLite = require('errsole-sqlite');
errsole.initialize({
storage: new ErrsoleSQLite('/tmp/logs.sqlite')
});
module.exports = errsole;
Now, you can import the logger.js
file in every file in your project and use it to log:
const logger = require('./logger');
// Example usage
logger.info('This is an informational message.');
logger.error('This is an error message.');
Understanding Log Levels in Errsole
Errsole Logger functions take the same arguments as console.log
. You can provide one or more strings, objects, or variables separated by a comma. Additionally, you can attach metadata to your log messages using the meta function. This metadata can be any contextual information, such as HTTP requests or database query results.
logger.meta({ reqBody: req.body, queryResults: results }).error(err);
logger.meta({ email: req.body.email }).log('User logged in');
Errsole Logger provides functions for five log levels: alert, error, warn, info, and debug.
log / info: Use to log messages or information.
logger.log('Logging a message');
logger.log('Multiple', 'arguments', 'are supported');
logger.log('Logging with a variable:', var1);
logger.log(new Error('An error occurred'));
logger.log('Logging with an error object:', errorObject);
alert: Logs a message and sends a notification to configured channels, such as Email or Slack.
logger.alert('Alert! Something critical happened');
error: Specifically designed to log errors.
logger.error(new Error('An error occurred'));
warn: Logs warning messages.
logger.warn('This is a warning message');
debug: Logs debug information, typically used for troubleshooting during development.
logger.debug('Debugging information');
When to use logger.alert
in your code
Whenever your Node.js application crashes, Errsole sends a real-time notification to your development team. This notification includes the error message, the app name, the environment name, and the server name.
To add critical errors to this notification list, use logger.alert
in your code. However, avoid overusing it to prevent flooding your developers with notifications. Use it for critical errors like payment failures or database query failures. Put the error object in the alert function and add all contextual information in the meta function. This allows developers to easily debug critical errors.
logger.meta({ reqBody: req.body, queryResults: results }).alert(err);
Conclusion
Incorporating a complete logging solution into your Node.js application ensures robust log management and efficient debugging. Errsole provides log storage, a built-in dashboard, and real-time notifications, making it a complete logging tool.
To get started with Errsole, visit https://github.com/errsole/errsole.js.
Top comments (14)
By integrating Errsole, your logger does more than just record error and performance data—it automatically captures detailed logs and sends them to a centralized dashboard. This streamlines the process of diagnosing and resolving issues, helping to improve the stability and maintainability of your applications in production.
Great article! It really explains Errsole as a full-fledged logging tool for Node.js. I really liked the detailed breaking down from real-time notifications on errors to the built-in dashboard. It's good to realize that Errsole can replace traditional log collectors and even enhance error management with its functionality. Will definitely let my colleagues know about this awesome library!
This is a great and insightful article that really explains the benefits of using advanced logging tools in Node.js projects.
Errsole is a comprehensive Node.js logger and debugger that combines features like log storage, real-time alerts, dashboards, and error tracking in one tool. It’s ideal for high-traffic applications and simplifies error management. Compared to popular libraries like Winston and Pino, Errsole offers more all-in-one capabilities, making it a great choice for efficient debugging and logging in both large and small projects.
If you’re looking for a comprehensive tool, Errsole is definitely worth considering.
Thank you for this post..
Reading this blog, I got to know how errsole is advantageous over other logging libraries.
It is not just a log collector but provides the whole logging solution, is easy to integrate into our application, enables us to attach meta data to log messages and also has the log level "alert" which is very beneficial for critical errors but should not be overused.
"Thank you for the detailed explanation of Errsole's capabilities. The integrated dashboard, real-time alerts, and error tracking, which together make it a super-advanced logging solution for node.js applications with high traffic, have been highly valued. I’m curious about how Errsole handles performance overhead in large-scale applications with extensive logging, especially when using the alert function frequently." Although it is possible to introduce some minor latency, is there a preferred way to manage it effectively? I am anticipating trying it out in my projects!"
This article offers a detailed guide on creating a custom logger for Node.js using Errsole. It highlights the importance of effective logging for real-time error monitoring and debugging, enhancing application reliability and maintainability in production environments.
A concise guide on integrating Errsole for complete logging in Node.js. It covers setting up custom loggers, managing log storage, and using real-time alerts. Perfect for developers looking for a robust all-in-one logging solution!
In the case of multiple errors, how does Errsole prioritize the most critical error that needs to be addressed first?
Great question....
I got to know that , Errsole prioritizes critical errors using the logger.alert function, which sends real-time notifications for high-priority issues like payment or database failures. Developers can include detailed contextual information using logger.meta to help quickly identify and resolve these critical problems. By focusing on key errors without flooding notifications, Errsole ensures that the most urgent issues get addressed first.
I hope this answer is clear and useful.
Thank you
A complete solutions for logging in Node.js, also providing a log storage, a dashboard and real time notifications for continuous updates. This guide is very helpful to understand what Erssole comes with and how to install and use it in Node.js applications.
In this blog, we learned that creating a custom logger for a Node.js application helps you track important events, errors, and information in a way that fits your specific needs. By building your own logger, you can format logs, set different log levels (like info, warning, error), and decide where to save these logs (such as in files or a database). This approach makes debugging and monitoring your application easier and more effective.
Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more