Support Logging setup Node.js logging

Node.js Logging

You can send your Node.js logs using our winston-loggly-bulk package. It sends logs directly from your application to Loggly using the HTTP/S Event API. The node logging has been tested with node versions 6.10.1 and 7.9.0. For alternatives, please see the Advanced Options section.

Node.js Logging Setup

1. Install the winston-loggly-bulk package

Install the loggly-winston-bulk package using NPM or from Github

npm install winston
npm install winston-loggly-bulk

2. Configure loggly-winston-bulk

Paste the following code to create a Loggly client.

var winston  = require('winston');
require('winston-loggly-bulk');
 
 winston.add(winston.transports.Loggly, {
    inputToken: "TOKEN",
    subdomain: "SUBDOMAIN",
    tags: ["Winston-NodeJS"],
    json:true
});

winston.log('info',"Hello World from Node.js!");

Replace:

    • TOKEN: your customer token from the source setup page
    • SUBDOMAIN: the subdomain of your Loggly account

3. Send Test Events

Run your application to send test events to Loggly.

4. Verify Events

Search Loggly for events with the Winston-NodeJS tag over the past 20 minutes. It may take a few minutes to index the event. If it doesn’t work, see the troubleshooting section below.

tag:Winston-NodeJS

Click on one of the logs to show a list of JSON fields (see screenshot below). If you don’t see them, please check that you are using one of our automatically parsed formats.

NodeJs-Screenshot

Advanced Node.js Logging Options

  • Package Docs – Describes how to send JSON objects, arrays, use tags, and more
  • node-Loggly-bulk – Use the node-loggly-bulk library to send node.js logs
  • bunyan-loggly – Use the bunyan library which has a wrapper for node-loggly
  • log4js – Use the log4js library which has a wrapper for node-loggly
  • HTTP/S Bulk Endpoint – Send up to 5MB batches of logs over HTTP/S for higher performance
  • This library has a buffer support during temporary network outage. User can configure size of buffer (no. of logs to be stored during network outage).
    Add the below configuration to override the default values of buffer option size and retriesInMilliSeconds in step 2.

    bufferOptions: {
        size: 1000,
        retriesInMilliSeconds: 60 * 1000
        }  
    

    Note: The default value of buffer size and retries in milliseconds are 500 and 30000 (30 seconds) respectively.

  • Loggly Libraries Catalog – New libraries are added to our catalog
  • Search or post your own Node.js logging or custom logging questions in the community forum.

Troubleshooting Node.js Logs

If you don’t see any data show up in the verification step, then check for these common problems.

Check winston-loggly-bulk:

  • Wait a few minutes in case indexing needs to catch up
  • See our HTTP Troubleshooting Guide to verify HTTP events are being sent to Loggly.

Still Not Working?

  • Search or post your own questions on Node.js logging levels, file transport, log messages, and more in the community forum.
Thanks for the feedback! We'll use it to improve our support documentation.