From 3bb022603a2272a7f16c53b6b1f722c530abd93b Mon Sep 17 00:00:00 2001 From: Abhilash Date: Tue, 24 Dec 2024 19:28:41 +0530 Subject: [PATCH] chore: added setLoggerLevel method --- packages/collector/src/logger.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/collector/src/logger.js b/packages/collector/src/logger.js index 69cf27ee5..07eb3ee8f 100644 --- a/packages/collector/src/logger.js +++ b/packages/collector/src/logger.js @@ -69,11 +69,11 @@ exports.init = function init(config, isReInit) { ); if (process.env['INSTANA_DEBUG']) { - parentLogger.level = 'debug'; + setLoggerLevel(parentLogger, 'debug'); } else if (config.level) { - parentLogger.level = config.level; + setLoggerLevel(parentLogger, config.level); } else if (process.env['INSTANA_LOG_LEVEL']) { - parentLogger.level = process.env['INSTANA_LOG_LEVEL'].toLowerCase(); + setLoggerLevel(parentLogger, process.env['INSTANA_LOG_LEVEL'].toLowerCase()); } } @@ -130,3 +130,15 @@ function hasLoggingFunctions(_logger) { typeof _logger.error === 'function' ); } + +/** + * @param {import("@instana/core/src/core").GenericLogger} _logger + * @param {string|number} level + */ +function setLoggerLevel(_logger, level) { + if (typeof _logger.setLevel === 'function') { + _logger.setLevel(level); + } else { + _logger.level = level; + } +}