Skip to content

Commit 06839aa

Browse files
naveenpaul1romayalon
authored andcommitted
NC | Noobaa syslogs are sent to two different files
Signed-off-by: naveenpaul1 <[email protected]> (cherry picked from commit 8b310d6)
1 parent 75de456 commit 06839aa

File tree

8 files changed

+70
-16
lines changed

8 files changed

+70
-16
lines changed

config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const _ = require('lodash');
1414
const util = require('util');
1515
const nsfs_schema_utils = require('./src/manage_nsfs/nsfs_schema_utils');
1616
const range_utils = require('./src/util/range_utils');
17+
const { EventEmitter } = require('events');
18+
19+
config.event_emitter = new EventEmitter();
1720

1821
/////////////////////////
1922
// CONTAINER RESOURCES //
@@ -464,8 +467,8 @@ config.EVENT_FACILITY = 'LOG_LOCAL2';
464467
config.EVENT_LOGGING_ENABLED = true;
465468
config.EVENT_LEVEL = 5;
466469

467-
config.LOG_TO_SYSLOG_ENABLED = true;
468470
config.LOG_TO_STDERR_ENABLED = true;
471+
config.LOG_TO_SYSLOG_ENABLED = false;
469472

470473
// TEST Mode
471474
config.test_mode = false;
@@ -1078,6 +1081,7 @@ function load_nsfs_nc_config() {
10781081
});
10791082
console.warn(`nsfs: config_dir_path=${config.NSFS_NC_CONF_DIR} config.json= ${util.inspect(merged_config)}`);
10801083
validate_nc_master_keys_config(config);
1084+
config.event_emitter.emit("config_updated");
10811085
} catch (err) {
10821086
if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ENOENT') throw err;
10831087
console.warn('config.load_nsfs_nc_config could not find config.json... skipping');

src/native/fs/fs_napi.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2123,7 +2123,18 @@ set_debug_level(const Napi::CallbackInfo& info)
21232123
{
21242124
int level = info[0].As<Napi::Number>();
21252125
DBG_SET_LEVEL(level);
2126-
DBG1("FS::set_debug_level " << level);
2126+
LOG("FS::set_debug_level " << level);
2127+
return info.Env().Undefined();
2128+
}
2129+
2130+
static Napi::Value
2131+
set_log_config(const Napi::CallbackInfo& info)
2132+
{
2133+
bool stderr_enabled = info[0].As<Napi::Boolean>();
2134+
bool syslog_enabled = info[1].As<Napi::Boolean>();
2135+
LOG_TO_STDERR_ENABLED = stderr_enabled;
2136+
LOG_TO_SYSLOG_ENABLED = syslog_enabled;
2137+
LOG("FS::set_log_config: " << DVAL(LOG_TO_STDERR_ENABLED) << DVAL(LOG_TO_SYSLOG_ENABLED));
21272138
return info.Env().Undefined();
21282139
}
21292140

@@ -2260,6 +2271,7 @@ fs_napi(Napi::Env env, Napi::Object exports)
22602271

22612272
exports_fs["dio_buffer_alloc"] = Napi::Function::New(env, dio_buffer_alloc);
22622273
exports_fs["set_debug_level"] = Napi::Function::New(env, set_debug_level);
2274+
exports_fs["set_log_config"] = Napi::Function::New(env, set_log_config);
22632275

22642276
exports["fs"] = exports_fs;
22652277
}

src/native/nb_native.gyp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
'util/struct_buf.h',
6767
'util/struct_buf.cpp',
6868
'util/common.h',
69+
'util/common.cpp',
6970
'util/napi.h',
7071
'util/napi.cpp',
7172
'util/os.h',
@@ -104,6 +105,7 @@
104105
'util/buf.cpp',
105106
'util/buf.h',
106107
'util/common.h',
108+
'util/common.cpp',
107109
'util/compression.cpp',
108110
'util/compression.h',
109111
'util/gf2.h',

src/native/util/common.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "common.h"
2+
3+
namespace noobaa
4+
{
5+
bool LOG_TO_STDERR_ENABLED = true;
6+
bool LOG_TO_SYSLOG_ENABLED = false;
7+
}

src/native/util/common.h

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "backtrace.h"
2020
#include "os.h"
21+
#include "syslog.h"
2122

2223
namespace noobaa
2324
{
@@ -28,19 +29,46 @@ namespace noobaa
2829

2930
#define DVAL(x) #x "=" << x << " "
3031

31-
#define LOG(x) std::cerr << LOG_PREFIX() << x << std::endl
32+
extern bool LOG_TO_STDERR_ENABLED;
33+
extern bool LOG_TO_SYSLOG_ENABLED;
34+
35+
#define STD_LOG(x) \
36+
do { \
37+
std::cerr << x << std::endl; \
38+
} while (0)
39+
40+
#define SYS_LOG(x) \
41+
do { \
42+
const char* log_msg = x.c_str(); \
43+
int facility = LOG_LOCAL0; \
44+
int priority = 0; \
45+
::syslog(priority | facility, "%s", log_msg); \
46+
} while (0)
47+
48+
#define LOG(x) \
49+
do { \
50+
std::ostringstream oss; \
51+
oss << "" << LOG_PREFIX() << x; \
52+
std::string message = oss.str(); \
53+
if (LOG_TO_STDERR_ENABLED) { \
54+
STD_LOG(message); \
55+
} \
56+
if (LOG_TO_SYSLOG_ENABLED) { \
57+
SYS_LOG(message); \
58+
} \
59+
} while (0)
3260

3361
// to use DBG the module/file should use either DBG_INIT or DBG_INIT_VAR.
3462
#define DBG_INIT(level) static int __module_debug_var__ = level
3563
#define DBG_INIT_VAR(debug_var) static int& __module_debug_var__ = debug_var
3664
#define DBG_SET_LEVEL(level) __module_debug_var__ = level
3765
#define DBG_GET_LEVEL() (__module_debug_var__)
3866
#define DBG_VISIBLE(level) (level <= __module_debug_var__)
39-
#define DBG(level, x) \
40-
do { \
41-
if (DBG_VISIBLE(level)) { \
42-
LOG("[L" << level << "] " << x); \
43-
} \
67+
#define DBG(level, x) \
68+
do { \
69+
if (DBG_VISIBLE(level)) { \
70+
LOG("[L" << level << "] " << x); \
71+
} \
4472
} while (0)
4573
#define DBG0(x) DBG(0, x)
4674
#define DBG1(x) DBG(1, x)

src/sdk/nb.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ interface NativeFS {
942942

943943
dio_buffer_alloc(size: number): Buffer;
944944
set_debug_level(level: number);
945+
set_log_config(stderr_enabled: boolean, syslog_enabled: boolean,);
945946

946947
S_IFMT: number;
947948
S_IFDIR: number;

src/server/bg_services/semaphore_monitor.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class SemaphoreMonitor {
2727
}
2828

2929
async run_batch() {
30-
dbg.log1("semaphore_monitor: START");
3130
if (!this._can_run()) return;
3231
try {
3332
this.run_semaphore_monitor();

src/util/debug_module.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ util.inspect.defaultOptions.depth = 10;
4141
util.inspect.defaultOptions.colors = true;
4242
util.inspect.defaultOptions.breakLength = Infinity;
4343

44-
4544
//Detect our context, node/atom/browser
4645
//Different context requires different handling, for example rotating file steam usage or console wrapping
4746
let syslog;
@@ -586,10 +585,12 @@ if (console_wrapper) {
586585
console_wrapper.register_logger(conlogger);
587586
}
588587

589-
let native_log_level = LOG_LEVEL;
590-
if (process.env.NOOBAA_LOG_LEVEL) {
591-
native_log_level = dbg_conf.level;
592-
}
593-
if (Number(native_log_level)) {
594-
nb_native().fs.set_debug_level(Number(native_log_level));
588+
589+
function set_log_config() {
590+
const dbg_native_conf = debug_config.get_debug_config(process.env.NOOBAA_LOG_LEVEL);
591+
nb_native().fs.set_debug_level(dbg_native_conf.level);
592+
nb_native().fs.set_log_config(config.LOG_TO_STDERR_ENABLED, config.LOG_TO_SYSLOG_ENABLED);
595593
}
594+
595+
config.event_emitter.on("config_updated", set_log_config);
596+
set_log_config();

0 commit comments

Comments
 (0)