WInston Loki not printing debug logs

76 views Asked by At

I am using winston Loki transport to print my logs using Loki host with a npm package winston-loki. Here my logger.info based logs are printing fine. But my logger.debug is not printing at all even I tried by setting log levels in the Loki transport object initialization,

Here is the code for Loki initialization.

logger.js

getLogger: function () {
  const logger = createLogger({
      transports: [new LokiTransport({
          host: "http://lokitransporturl.com",
          port: 3100,
          labels: { app: 'honeyshop'},
          json: true,
          level: 'debug', // Set multiple log levels
          format: format.json(),
          replaceTimestamp: true,
          onConnectionError: (err) => {
            console.error('Loki onConnectionError '+err)
          }
        }),
        new transports.Console({
          format: format.combine(format.simple(), format.colorize())
        })]
    })
    return logger;
  }

app.js

const lokiLoggerFile = require('./logger);
global.lokiLogger = lokiLoggerFile.getLogger();

myfile.js

lokiLogger.info({ message: `Test info msg for loki logger`, labels: { 'origin': '/username' }})
lokiLogger.debug({ message: `Test debug msg for loki logger`, labels: { 'origin': '/username' }})

Here the first line with info logger is getting printed and second line with debug logger is not printed.

level: ['info', 'debug'], // Only printing info logs

level: 'debug', // Only printing info logs

level: ['info'], // Only printing info logs

I tried these options in the log level set up in logger.js but still debug logs is not visible in loki user interface.

Actual intention here is to show only desired level of logs. Let say, I want only info and error logs. In other hand I want to display only info and debug logs. So I want the level of logs should be optional to use. Any help would be appreciate here.

0

There are 0 answers