Winston Logstash Config For Node.js
Ship logs from your Node.js application to logstash
The example code used in this guide has been setup using Node.js v14.17.0 (64-bit). Node Package Manager (npm) can be used to install the required
winston (3.3.3) and
winston-logstash (0.4.0) packages.
These will allow us to send log data from our Node.js application, to Logstash using the example code used in this guide has been setup using Node.js v8.11.3 (64-bit). Node Package Manager (npm) can be used to install the required winston (2.4.1) and winston-logstash (0.4.0) packages. These will allow us to send log data from our Node.js application, to TCP with SSL enabled.
The official winston documentation can be found here.
Follow this step by step guide to get 'logs' from your system to Logit.io:
Step 1 - Installing
First, ensure that you have downloaded and installed Node.js (32 or 64 bit). You can get it from the official website, here. This includes various options to install including using an installer file (for Windows or Mac).
If you are just starting out with sending logs via Node.js there is a useful tutorial for creating an 'express' application to help get you up-and-running here.
Inside your project directory, open a terminal of your choice and type the following:
npm install [email protected] npm install [email protected]
Step 2 - Sending Logs
Step 3 - Check Logit.io for your logs
Now you should view your data:
If you don't see logs take a look at How to diagnose no data in Stack below for how to diagnose common issues.
Step 4 - how to diagnose no data in Stack
If you don't see data appearing in your Stack after following the steps, visit the Help Centre guide for steps to diagnose no data appearing in your Stack or Chat to support now.
Step 5 - Node.JS Logging Overview
Winston is the most popular logging library for Node.js as it makes logging more flexible & can be configured to multiple levels.
Winston is well known for its robust feature set & easy installation which we have detailed in this configuration guide. Morgan is commonly used in association with Winston and operates as an HTTP request logger middleware for Node.js.
Parsing, transforming & analysing emergency, critical & error Node.js logs can be hard to perform at scale from the default logging format. Priority messages can easily get lost in the noise of other logging formats (such as Info & Notice) and are not alerted on to be resolved by your wider DevOps team.
Logit.io provides a complete Node.js log analyser by default as part of our log management platform, this includes alerting, collection & visualisations enhancing your text logs to provide data-driven insights & real-time log tailing.
If you need any more assistance with migrating your Node.js data to Logstash we're here to help. Just get in contact with our support team via live chat & we'll be happy to assist.