From a277928fa3c4f8a16d1a7056864951b65888eb4a Mon Sep 17 00:00:00 2001 From: Quan HL Date: Mon, 7 Oct 2024 16:57:00 +0700 Subject: [PATCH] support change log level runtime --- app.js | 4 ++++ lib/middleware.js | 6 +++++- test/db/jambones-sql.sql | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 9ea4cb0..a5aec70 100644 --- a/app.js +++ b/app.js @@ -198,6 +198,10 @@ if ('test' !== process.env.NODE_ENV) { logger.info(`updating private network cidr from ${srf.locals.privateNetworkCidr} to ${r.private_network_cidr}`); srf.locals.privateNetworkCidr = r.private_network_cidr; } + // Update system log level + if (r.log_level) { + logger.level = r.log_level; + } } }, 20000); } diff --git a/lib/middleware.js b/lib/middleware.js index c8bb78a..a73c7cf 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -77,7 +77,11 @@ module.exports = (srf, logger, redisClient) => { }); try { - req.locals.account = await lookupAccountBySid(req.locals.account_sid); + const account = await lookupAccountBySid(req.locals.account_sid); + req.locals.account = account; + if (account.enable_debug_log) { + req.locals.logger.level = 'debug'; + } req.locals.service_provider_sid = req.locals.account.service_provider_sid; } catch (err) { req.locals.logger.error({err}, `Error looking up account sid ${req.locals.account_sid}`); diff --git a/test/db/jambones-sql.sql b/test/db/jambones-sql.sql index 2f367f2..8a9b80a 100644 --- a/test/db/jambones-sql.sql +++ b/test/db/jambones-sql.sql @@ -358,7 +358,9 @@ CREATE TABLE system_information ( domain_name VARCHAR(255), sip_domain_name VARCHAR(255), -monitoring_domain_name VARCHAR(255) +monitoring_domain_name VARCHAR(255), +private_network_cidr VARCHAR(8192), +log_level ENUM('info', 'debug') NOT NULL DEFAULT 'info' ); CREATE TABLE users @@ -552,6 +554,7 @@ siprec_hook_sid CHAR(36), record_all_calls BOOLEAN NOT NULL DEFAULT false, record_format VARCHAR(16) NOT NULL DEFAULT 'mp3', bucket_credential VARCHAR(8192) COMMENT 'credential used to authenticate with storage service', +enable_debug_log BOOLEAN NOT NULL DEFAULT false, PRIMARY KEY (account_sid) ) COMMENT='An enterprise that uses the platform for comm services';