Skip to content

Commit 75de456

Browse files
naveenpaul1romayalon
authored andcommitted
NC | Flag to control syslog and console log
Signed-off-by: naveenpaul1 <[email protected]> (cherry picked from commit 4873ae9)
1 parent 1c4ce8b commit 75de456

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ config.EVENT_FACILITY = 'LOG_LOCAL2';
464464
config.EVENT_LOGGING_ENABLED = true;
465465
config.EVENT_LEVEL = 5;
466466

467+
config.LOG_TO_SYSLOG_ENABLED = true;
468+
config.LOG_TO_STDERR_ENABLED = true;
469+
467470
// TEST Mode
468471
config.test_mode = false;
469472

docs/dev_guide/NonContainerizedDeveloperCustomizations.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,43 @@ Example:
458458
3. systemctl restart noobaa
459459
```
460460

461+
## 25. Syslog enable flag -
462+
**Description -** This flag will enable syslog logging for the application.
463+
464+
**Configuration Key -** LOG_TO_SYSLOG_ENABLED
465+
466+
**Type -** boolean
467+
468+
**Default -** true
469+
470+
**Steps -**
471+
```
472+
1. Open /path/to/config_dir/config.json file.
473+
2. Set the config key -
474+
Example:
475+
"LOG_TO_SYSLOG_ENABLED": true
476+
3. systemctl restart noobaa
477+
```
478+
479+
## 26. Stderr enable flag -
480+
**Description -** This flag will decide whether need to push logs to the stderr or not.
481+
482+
**Configuration Key -** LOG_TO_STDERR_ENABLED
483+
484+
**Type -** boolean
485+
486+
**Default -** false
487+
488+
**Steps -**
489+
```
490+
1. Open /path/to/config_dir/config.json file.
491+
2. Set the config key -
492+
Example:
493+
"LOG_TO_STDERR_ENABLED": false
494+
3. systemctl restart noobaa
495+
```
496+
497+
```
461498
> cat /path/to/config_dir/config.json
462499
{
463500
"ENDPOINT_PORT": 80,

src/server/system_services/schemas/nsfs_config_schema.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,15 @@ const nsfs_node_config_schema = {
139139
ENDPOINT_PROCESS_TITLE: {
140140
type: 'string',
141141
description: 'This flag will set noobaa process title for letting GPFS to identify the noobaa endpoint processes.'
142-
}
142+
},
143+
LOG_TO_SYSLOG_ENABLED: {
144+
type: 'boolean',
145+
doc: 'This flag will enable syslog logging for the application.'
146+
},
147+
LOG_TO_STDERR_ENABLED: {
148+
type: 'boolean',
149+
doc: 'This flag will decide whether need to push logs to the console or not.'
150+
},
143151
}
144152
};
145153

src/test/unit_tests/jest_tests/test_nc_nsfs_config_schema_validation.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
const nsfs_schema_utils = require('../../../manage_nsfs/nsfs_schema_utils');
66
const RpcError = require('../../../rpc/rpc_error');
7+
const config = require('../../../../config');
78

89
describe('schema validation NC NSFS config', () => {
910

@@ -251,6 +252,31 @@ describe('schema validation NC NSFS config', () => {
251252
nsfs_schema_utils.validate_nsfs_config_schema(config_data);
252253
});
253254
});
255+
256+
describe('skip/unskip schema check by config test', () => {
257+
258+
it('unskip schema check - config.LOG_TO_SYSLOG_ENABLED=false nsfs_config.LOG_TO_SYSLOG_ENABLED=bla - invalid config - should fail', () => {
259+
config.LOG_TO_SYSLOG_ENABLED = false;
260+
const config_data = {
261+
LOG_TO_SYSLOG_ENABLED: 'bla',
262+
};
263+
const reason = 'Test should have failed because of wrong type ' +
264+
'LOG_TO_SYSLOG_ENABLED must be boolean';
265+
const message = `must be boolean | {"type":"boolean"} | "/LOG_TO_SYSLOG_ENABLED"`;
266+
assert_validation(config_data, reason, message);
267+
});
268+
269+
it('unskip schema check - config.LOG_TO_STDERR_ENABLED=false nsfs_config.LOG_TO_STDERR_ENABLED=bla - invalid config - should fail', () => {
270+
config.LOG_TO_STDERR_ENABLED = false;
271+
const config_data = {
272+
LOG_TO_STDERR_ENABLED: 'bla',
273+
};
274+
const reason = 'Test should have failed because of wrong type ' +
275+
'LOG_TO_STDERR_ENABLED must be boolean';
276+
const message = `must be boolean | {"type":"boolean"} | "/LOG_TO_STDERR_ENABLED"`;
277+
assert_validation(config_data, reason, message);
278+
});
279+
});
254280
});
255281

256282
function assert_validation(config_to_validate, reason, basic_message) {

src/util/debug_module.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ class InternalDebugLogger {
379379
}
380380

381381
log_internal(msg_info) {
382-
if (syslog) {
382+
if (syslog && config.LOG_TO_SYSLOG_ENABLED) {
383383
// syslog path
384384
syslog(this._levels_to_syslog[msg_info.level], msg_info.message_syslog, config.DEBUG_FACILITY);
385385
} else if (this._log_file) {
@@ -389,7 +389,7 @@ class InternalDebugLogger {
389389
// This is also used in order to log to the console
390390
// browser workaround, don't use rotating file steam. Add timestamp and level
391391
const logfunc = LOG_FUNC_PER_LEVEL[msg_info.level] || 'log';
392-
if (this._log_console_silent) {
392+
if (this._log_console_silent || !config.LOG_TO_STDERR_ENABLED) {
393393
// noop
394394
} else if (console_wrapper) {
395395
process.stderr.write(msg_info.message_console + '\n');

0 commit comments

Comments
 (0)