Node.js

Collect logs from any Node.js applications.

Installation

Using NPM

npm i @logshq.io/node --save

Using Yarn

yarn add @logshq.io/node

If you don't have yarn installed, install it globally:

npm install --global yarn

Example

The library is really easy to work with, simply import it and use your Stream and Project API keys

logger.js
const LogshqLogger = require('@logshq.io/node');

// Credentials
const logger = new LogshqLogger({
  project_id: 'SOME-PROJECT-ID',
  api_key: 'SOME-STREAM-KEY',
  environment: process.env.NODE_ENV, // optional
  hostname: 'auth-service', // optional
});

// debug; one of the library's methods
logger.debug('Email successfully sent after registration', {
  step: 'Step 3',
  method: 'signUp',
  module: 'auth.js',
  correlationId: '326126b5-6918-4624-8c19-0730587c5cd6'
});

// export logger for later use
module.exports = logger

As a result, the following JSON rows will be ingested

{
  "environment": "production",
  "facility": "Node.js",
  "facility_version": "v16.17.1",
  "library_version": "V1",
  "hostname": "auth-service",
  "metaData": {
    "step": "Step 3",
    "method": "signUp",
    "module": "auth.js",
    "correlationId": "326126b5-6918-4624-8c19-0730587c5cd6"
  },
  "level": "debug",
  "message": "Email successfully sent after registration",
  "timestamp": "2023-01-22T22:44:27.320Z",
  "uuid": "d50cfb9e-0a9e-4a35-9b62-3e798d951bba"
}

You can perform search using any of the data that you have sent once the log is received:

You can view it in a modal for more details.

Configuration options

Last updated