Skip to content

Node.js Winston

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

Choose the https://ingress./logs/v1/singles endpoint that corresponds to your Coralogix domain using the domain selector at the top of the page.

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.

Winston HTTP Transport

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: "https://ingress.",
            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
Coralogix EndpointsCoralogix Endpoints

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.

Was this helpful?