Our next-gen architecture is built to help you make sense of your ever-growing data. Watch a 4-min demo video!

Back to All Docs

Node.js Winston Node.js Winston

Last Updated: Dec. 21, 2023

This guide provides step-by-step instructions and essential insights to seamlessly incorporate Coralogix into your Node.js Winston setup, ensuring efficient and centralized log management for your applications.

Endpoint URL

Input the Coralogix REST API Singles endpoint corresponding to your Coralogix domain.

Variables

You must provide the following four variables when creating a Coralogix logger instance.

API Key – Your Send-Your-Data API key is a unique ID representing your company.

Application Name – The name of your environment; for example, a company named “SuperData” would probably insert the “SuperData” string parameter, or if they want to debug their test environment, they might insert the “SuperData– Test”.

SubSystem Name – Your application probably has multiple components, for example, backend servers, middleware, frontend servers, etc., and to help you examine the data you need, inserting the subsystem parameter is vital.

For more information on how to set up and use Winston, check out our guide and the Winston repository.

Winston Usage Example

const os = require("os");
const winston = require("winston");


const logger = winston.createLogger({
    transports: [
        new winston.transports.Http({
            name: "coralogix",
            level: "info",
            format: winston.format((info) => ({
                applicationName: "nodejs",
                subsystemName: "winston",
                computerName: os.hostname(),
                timestamp: Date.now(),
                severity: {
                    silly: 1,
                    debug: 1,
                    verbose: 2,
                    info: 3,
                    warn: 4,
                    error: 5,
                    critical: 6
                }[info.level] || 3,
                text: info.message,
            }))(),
            host: "<DOMAIN_URL>",
            path: "logs/v1/singles",
            headers: {
                "authorization": "Bearer <Send-your-data-api_key>"
            },
            ssl: true,
            batchInterval: 1000,
            handleExceptions: true
        })
    ],
    exitOnError: false
});

logger.info("My info log line");

Note: If using TypeScript, set the ‘esModuleInterop’ configuration option to true in your tsconfig.json to allow imports of both CommonJS (os) and ES6 (Winston) modules, as both are used in the example code.

Additional Resources

BlogComplete Winston Logger Guide

Support

Need help?

Our world-class customer success team is available 24/7 to walk you through your setup and answer any questions that may come up.

Feel free to reach out to us via our in-app chat or by sending us an email at support@coralogix.com.

On this page