Most applications on the web use Node to process multiple asynchronous events in unison. Its high scalability in handling a constantly increasing volume of requests gives this framework an edge over the other options. It is at the center of a MEAN stack’s framework, serving data quickly and efficiently. Express.js is purpose-built to work with both Node.js and Angular.js.
Existing log management for Node
Node has an expansive logging functionality that is structured using JSON with advanced logging patterns and recorded data fields. Both on-prem and cloud-native Node applications have two logging options; logging to an exportable file or forwarding logs directly to a log management application. Logging Node.js applications is done via third-party logging libraries such as Winston, Pino, and Morgan.
For containerized and orchestrated applications built on the MEAN stack framework, it is recommended to use the console’s transport option to create the path to finally output logs to the container/ orchestrator’s centralized logging location.
Winston is the logging library of choice for most MEAN stack applications. Winston gives the extensibility and flexibility needed to log large application events. Using Winston as your log shipper you can:
- Define logging levels based on your application needs. Adding a logging level increases the visibility into severe issues and assists with creating a meaningful categorization for any application activity. By default, Winston logs events based on the npm priority protocol that categorizes logs into six priority levels ranging from 0 to 5, 0 being the most critical and 5 the least in severity. Alternatively, you can set to follow the Syslog protocols.
- Winston offers three log transport options, console, file, and HTTP. The term transport is used in Winston to denote the storage and output of logs.
- Adding meaningful and diagnostic metadata to your logs both globally and locally. This is a foolproof way to read the fine-grain details of application requests during troubleshooting. For instance, adding the user’s geographic location to access logs helps identify application issues affecting users from specific geography.
- Categorization and sub-categorization options for adding more context to logs.
- Logging in JSON is always the best way to output your logs for easy parsing into a log management application.
- Use Winston’s exception handling library to log application exceptions. Winston does not log exceptions by default.
Pino is a fast logging option for MEAN stack applications. It offers a command-line logging interface that decouples the log processing, alerting, and reformatting into separate processes, to overcome Node’s single-threaded event loop. For faster performance, Pino offers an extreme mode setting. In this mode, logs are written directly to the output stream to increase efficiency. Pino does this in chunks and this is the downside of using Pino because chunk output may result in missing out some logs when there’s downtime or outage.
Morgan simplifies the process of logging HTTP requests. It is a logging library and not a log shipper like Winston. The automatic logging capabilities of Morgan save time for developers by eliminating the need to manually code the application to log all HTTP requests. Morgan logs in the Apache combined log format and it needs Winston to forward the logs to any external application for analysis and log management.
Existing log management for Mongo Logs
By default, MongoDB outputs logs in the JSON format for database events such as entries, commands run, and issues. In container orchestrated applications, MongoDB offers a plethora of options to monitor the cluster. When troubleshooting the log granularity can be fine-tuned to get insights into every detail in the database. The most critical log information you can read and actions that you can take to make logs from Mongo useful:
- The general health of the database, factoring the uptime, and a time-wise availability for each of the database counters.
- In the case of containerized and orchestrated applications, the server and database sharing performance statistics are deciphered from inspecting the performance of the daemon and cluster components.
- Server performance logs can give a statistical overview of the time taken to execute a query based on a collection or the database in its entirety.
- Set log verbosity levels or view logs in a command-line interface for elaborate analysis.
- Gauging loads limits and setting thresholds based on currently available infrastructure.
Mongo offers a free log monitoring service named Mongo Atlas, which aggregates Mongo logs and provides insightful metrics. This is exclusive to Mongo logs only and not applicable to the whole stack.
We have a more streamlined and cohesive approach to MEAN stack application in the works. This solution brings unparalleled visibility into your logs and gives you much-needed relief from numerous configurations and preset alterations to aggregate your logs into a unified interface. Follow our blogs to get updates related to this.