Skip to content

Commit

Permalink
NC | Flag to control syslog and console log
Browse files Browse the repository at this point in the history
Signed-off-by: naveenpaul1 <[email protected]>
  • Loading branch information
naveenpaul1 committed Jun 13, 2024
1 parent 7a5b626 commit 4873ae9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
3 changes: 3 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
37 changes: 37 additions & 0 deletions docs/dev_guide/NonContainerizedDeveloperCustomizations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion src/server/system_services/schemas/nsfs_config_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
},
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/util/debug_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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');
Expand Down

0 comments on commit 4873ae9

Please sign in to comment.