From d303194b3d63561b6c3da20d00173e528d600da5 Mon Sep 17 00:00:00 2001 From: Yossi Eynav Date: Sun, 21 Apr 2024 20:42:57 +0300 Subject: [PATCH] refactor(logger): run only on staging and prod --- server/api/lib/log.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/server/api/lib/log.js b/server/api/lib/log.js index d07851fc..12219177 100644 --- a/server/api/lib/log.js +++ b/server/api/lib/log.js @@ -3,16 +3,16 @@ const os = require('os'); const util = require('util') const Config = require('./config'); -const apikey = Config.get('coralogix.apikey'); -const serviceName = Config.get('coralogix.serviceName'); -const host = Config.get('coralogix.host'); +const transports = [ + new winston.transports.Console() +] -const logger = winston.createLogger({ - level: 'info', - format: winston.format.json(), - defaultMeta: { version: process.env.VERSION, env: process.env.NODE_ENV }, - transports: [ - new winston.transports.Console(), +if (process.env.NODE_ENV === "staging" || process.env.NODE_ENV === "production") { + const apikey = Config.get('coralogix.apikey'); + const serviceName = Config.get('coralogix.serviceName'); + const host = Config.get('coralogix.host'); + + transports.push( new winston.transports.Http({ name: "coralogix", level: "info", @@ -59,7 +59,14 @@ const logger = winston.createLogger({ batchInterval: 1000, handleExceptions: true, }), - ] + ) + +} +const logger = winston.createLogger({ + level: 'info', + format: winston.format.json(), + defaultMeta: { version: process.env.VERSION, env: process.env.NODE_ENV }, + transports, }); module.exports = {