Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: load env in logger and fix logLevel condition logic
Browse files Browse the repository at this point in the history
ItsSudip committed Jun 12, 2024
1 parent 827157b commit 12a4ce2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/logger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const dotenv = require('dotenv');

/* istanbul ignore file */
const { structuredLogger: logger /* LOGLEVELS */ } = require('@rudderstack/integrations-lib');

dotenv.config({ path: '../.env' });

const LOGLEVELS = {
debug: 0, // Most verbose logging level
info: 1, // Logs about state of the application
@@ -71,35 +75,35 @@ const getLogger = () => {

const debug = (...args) => {
const logger = getLogger();
if (logLevel >= LOGLEVELS.debug) {
if (LOGLEVELS.debug >= logLevel) {
log(logger.debug, args);
}
};

const info = (...args) => {
const logger = getLogger();
if (logLevel >= LOGLEVELS.info) {
if (LOGLEVELS.info >= LOGLEVELS[logLevel]) {
log(logger.info, args);
}
};

const warn = (...args) => {
const logger = getLogger();
if (logLevel >= LOGLEVELS.warn) {
if (LOGLEVELS.warn >= LOGLEVELS[logLevel]) {
log(logger.warn, args);
}
};

const error = (...args) => {
const logger = getLogger();
if (logLevel >= LOGLEVELS.error) {
if (LOGLEVELS.error >= LOGLEVELS[logLevel]) {
log(logger.error, args);
}
};

const requestLog = (identifierMsg, { metadata, requestDetails: { url, body, method } }) => {
const logger = getLogger();
if (logLevel === LOGLEVELS.warn) {
if (LOGLEVELS[logLevel] === LOGLEVELS.warn) {
const reqLogArgs = [identifierMsg, { metadata, url, body, method }];
log(logger.warn, reqLogArgs);
}
@@ -110,7 +114,7 @@ const responseLog = (
{ metadata, responseDetails: { response: body, status, headers } },
) => {
const logger = getLogger();
if (logLevel === LOGLEVELS.warn) {
if (LOGLEVELS[logLevel] === LOGLEVELS.warn) {
const resLogArgs = [identifierMsg, { metadata, body, status, headers }];
log(logger.warn, resLogArgs);
}

0 comments on commit 12a4ce2

Please sign in to comment.