From 4873ae91937b80da4bd331ba2b3577f389a53d50 Mon Sep 17 00:00:00 2001 From: naveenpaul1 Date: Thu, 13 Jun 2024 21:00:20 +0530 Subject: [PATCH] NC | Flag to control syslog and console log Signed-off-by: naveenpaul1 --- config.js | 3 ++ ...NonContainerizedDeveloperCustomizations.md | 37 +++++++++++++++++++ .../schemas/nsfs_config_schema.js | 10 ++++- ...t_nc_nsfs_config_schema_validation.test.js | 22 +++++++++++ src/util/debug_module.js | 4 +- 5 files changed, 73 insertions(+), 3 deletions(-) diff --git a/config.js b/config.js index 21efe131d4..a1449676c9 100644 --- a/config.js +++ b/config.js @@ -464,6 +464,9 @@ config.EVENT_FACILITY = 'LOG_LOCAL2'; config.EVENT_LOGGING_ENABLED = true; config.EVENT_LEVEL = 5; +config.LOG_TO_SYSLOG_ENABLED = true; +config.LOG_TO_STDERR_ENABLED = true; + // TEST Mode config.test_mode = false; diff --git a/docs/dev_guide/NonContainerizedDeveloperCustomizations.md b/docs/dev_guide/NonContainerizedDeveloperCustomizations.md index a1e4f97ebd..fb93b87e81 100644 --- a/docs/dev_guide/NonContainerizedDeveloperCustomizations.md +++ b/docs/dev_guide/NonContainerizedDeveloperCustomizations.md @@ -495,6 +495,43 @@ Example: 3. systemctl restart noobaa ``` +## 25. Syslog enable flag - +**Description -** This flag will enable syslog logging for the application. + +**Configuration Key -** LOG_TO_SYSLOG_ENABLED + +**Type -** boolean + +**Default -** true + +**Steps -** +``` +1. Open /path/to/config_dir/config.json file. +2. Set the config key - +Example: +"LOG_TO_SYSLOG_ENABLED": true +3. systemctl restart noobaa +``` + +## 26. Stderr enable flag - +**Description -** This flag will decide whether need to push logs to the stderr or not. + +**Configuration Key -** LOG_TO_STDERR_ENABLED + +**Type -** boolean + +**Default -** false + +**Steps -** +``` +1. Open /path/to/config_dir/config.json file. +2. Set the config key - +Example: +"LOG_TO_STDERR_ENABLED": false +3. systemctl restart noobaa +``` + +``` > cat /path/to/config_dir/config.json { "ENDPOINT_PORT": 80, diff --git a/src/server/system_services/schemas/nsfs_config_schema.js b/src/server/system_services/schemas/nsfs_config_schema.js index 625920c5d8..aaaa9ab7fa 100644 --- a/src/server/system_services/schemas/nsfs_config_schema.js +++ b/src/server/system_services/schemas/nsfs_config_schema.js @@ -129,7 +129,15 @@ const nsfs_node_config_schema = { ENDPOINT_PROCESS_TITLE: { type: 'string', doc: 'This flag will set noobaa process title for letting GPFS to identify the noobaa endpoint processes.' - } + }, + LOG_TO_SYSLOG_ENABLED: { + type: 'boolean', + doc: 'This flag will enable syslog logging for the application.' + }, + LOG_TO_STDERR_ENABLED: { + type: 'boolean', + doc: 'This flag will decide whether need to push logs to the console or not.' + }, } }; diff --git a/src/test/unit_tests/jest_tests/test_nc_nsfs_config_schema_validation.test.js b/src/test/unit_tests/jest_tests/test_nc_nsfs_config_schema_validation.test.js index 46fbe94c18..08f93960ec 100644 --- a/src/test/unit_tests/jest_tests/test_nc_nsfs_config_schema_validation.test.js +++ b/src/test/unit_tests/jest_tests/test_nc_nsfs_config_schema_validation.test.js @@ -339,6 +339,28 @@ describe('schema validation NC NSFS config', () => { const message = `must be boolean | {"type":"boolean"} | "/NC_DISABLE_SCHEMA_CHECK"`; assert_validation(config_data, reason, message); }); + + it('unskip schema check - config.LOG_TO_SYSLOG_ENABLED=false nsfs_config.LOG_TO_SYSLOG_ENABLED=bla - invalid config - should fail', () => { + config.LOG_TO_SYSLOG_ENABLED = false; + const config_data = { + LOG_TO_SYSLOG_ENABLED: 'bla', + }; + const reason = 'Test should have failed because of wrong type ' + + 'LOG_TO_SYSLOG_ENABLED must be boolean'; + const message = `must be boolean | {"type":"boolean"} | "/LOG_TO_SYSLOG_ENABLED"`; + assert_validation(config_data, reason, message); + }); + + it('unskip schema check - config.LOG_TO_STDERR_ENABLED=false nsfs_config.LOG_TO_STDERR_ENABLED=bla - invalid config - should fail', () => { + config.LOG_TO_STDERR_ENABLED = false; + const config_data = { + LOG_TO_STDERR_ENABLED: 'bla', + }; + const reason = 'Test should have failed because of wrong type ' + + 'LOG_TO_STDERR_ENABLED must be boolean'; + const message = `must be boolean | {"type":"boolean"} | "/LOG_TO_STDERR_ENABLED"`; + assert_validation(config_data, reason, message); + }); }); }); diff --git a/src/util/debug_module.js b/src/util/debug_module.js index 919712c3a5..1a98a76012 100644 --- a/src/util/debug_module.js +++ b/src/util/debug_module.js @@ -379,7 +379,7 @@ class InternalDebugLogger { } log_internal(msg_info) { - if (syslog) { + if (syslog && config.LOG_TO_SYSLOG_ENABLED) { // syslog path syslog(this._levels_to_syslog[msg_info.level], msg_info.message_syslog, config.DEBUG_FACILITY); } else if (this._log_file) { @@ -389,7 +389,7 @@ class InternalDebugLogger { // This is also used in order to log to the console // browser workaround, don't use rotating file steam. Add timestamp and level const logfunc = LOG_FUNC_PER_LEVEL[msg_info.level] || 'log'; - if (this._log_console_silent) { + if (this._log_console_silent || !config.LOG_TO_STDERR_ENABLED) { // noop } else if (console_wrapper) { process.stderr.write(msg_info.message_console + '\n');