Skip to content

Commit 6cb5714

Browse files
authored
Merge pull request #8207 from naveenpaul1/event_stderr_log
NSFS | Log events to stderr when stderr logging is enabled
2 parents 7015998 + 1c5effa commit 6cb5714

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

src/deploy/standalone/noobaa_syslog.conf

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,15 @@ $imjournalRatelimitBurst 0
1212
# When changing this format make sure to change the relevant functions in os_utils
1313
#if $syslogfacility-text != 'local0' then @192.168.1.108:514
1414

15-
template(name="LogseneFormat" type="list" option.json="on") {
16-
constant(value="{")
17-
constant(value="\"timestamp\":\"")
18-
property(name="timereported" dateFormat="rfc3339")
19-
constant(value="\",\"message\":\"")
20-
property(name="msg")
21-
constant(value="\",\"host\":\"")
22-
property(name="hostname")
23-
constant(value="\",\"severity\":\"")
24-
property(name="syslogseverity-text")
25-
constant(value="\",\"facility\":\"")
26-
property(name="syslogfacility-text")
27-
constant(value="\",\"syslog-tag\":\"")
28-
property(name="syslogtag")
29-
constant(value="\",\"source\":\"")
30-
property(name="programname")
31-
constant(value="\"}\n")
32-
}
33-
3415
# For servers
35-
local0.* /var/log/noobaa.log;RSYSLOG_FileFormat
16+
local0.* /var/log/noobaa.log
3617
&stop
3718

3819
# For events
39-
local2.* /var/log/noobaa_events.log;LogseneFormat
20+
local2.* /var/log/noobaa_events.log
4021
&stop
4122

4223
# For clients
43-
local1.* /var/log/client_noobaa.log;RSYSLOG_FileFormat
24+
local1.* /var/log/client_noobaa.log
4425
&stop
4526

src/util/debug_module.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,27 @@ function log_syslog_builder(syslevel) {
494494
};
495495
}
496496

497+
/* When logging events message should not have any prefix such as time and processes id and
498+
*the message should be in json format because of this events are logged directly without using log_builder;
499+
* log_builder will format the message with prefix.
500+
*/
497501
function log_event(event) {
498502
if (!config.EVENT_LOGGING_ENABLED) {
499503
console.info('Event logging not enabled');
500504
return;
501505
}
502506
event.pid = process.pid;
507+
const updated_event = JSON.stringify({
508+
timestamp: new Date(),
509+
host: os.hostname(),
510+
event: event,
511+
});
503512
if (syslog) {
504-
syslog(config.EVENT_LEVEL, JSON.stringify(event), config.EVENT_FACILITY);
513+
syslog(config.EVENT_LEVEL, updated_event, config.EVENT_FACILITY);
514+
}
515+
if (console_wrapper && config.LOG_TO_STDERR_ENABLED) {
516+
const formatted_event = int_dbg.message_format("EVENT", [updated_event]);
517+
process.stderr.write(formatted_event.message_console + '\n');
505518
}
506519
}
507520

0 commit comments

Comments
 (0)