node.jswinstonlogglymorgan

Loggly Subdomain is required


I'm trying to implement to my NodeJs API a logging system using:

When I run my server I got the error: Error: Loggly Subdomain is required

But the subdomain is defined as follows

What I was trying to do to put the Loggly config inside of a module:

module.exports = {
    loggly: {
        token: process.env.LOG_TOKEN,
        subdomain: process.env.SUBDOMAIN,
        tags: ["Winston-NodeJS"],
        json: true
    }
};

Using also the ENV which are defined and contains the right info.

Then I created a new file called logger.js

// Requiring libs Loggly & Winston
const Loggly = require("winston-loggly-bulk").Loggly;
const winston = require("winston");
// Loggly config
const config = require("../config/config");

// Creating the logging
const logger = winston.createLogger({
    transports: [
        new Loggly(config.loggly), ==> Here the error occur!
        new winston.transports.Console({ level: "info" })
    ]
});
// Logging stream
logger.stream = {
    write: (info) => {
        logger.info(info);
    }
};

module.exports = logger;

In this script, the error occurs when I call new Loggly(...) seems cannot read my SUBDOMAIN and I cannot understand a different way of doing as it is the first time I'm trying this implementation.


Solution

  • Put this line require("dotenv").config(); on line 1 in server.js.