Skip to content

Commit

Permalink
Merge pull request #8281 from aspandey/remove-log-colors
Browse files Browse the repository at this point in the history
noobaa/core: Modify debug module to chnge log color
  • Loading branch information
aspandey committed Aug 22, 2024
2 parents d19fdfd + 42f3ae7 commit dd4e50a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 2 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ config.EVENT_LEVEL = 5;
config.LOG_TO_STDERR_ENABLED = true;
config.LOG_TO_SYSLOG_ENABLED = false;

config.LOG_COLOR_ENABLED = process.env.NOOBAA_LOG_COLOR ? process.env.NOOBAA_LOG_COLOR === 'true' : true;

// TEST Mode
config.test_mode = false;

Expand Down
31 changes: 20 additions & 11 deletions src/util/debug_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (process.env.NOOBAA_LOG_LEVEL) {
// override the default inspect options
if (!util.inspect.defaultOptions) util.inspect.defaultOptions = {};
util.inspect.defaultOptions.depth = 10;
util.inspect.defaultOptions.colors = true;
util.inspect.defaultOptions.colors = config.LOG_COLOR_ENABLED;
util.inspect.defaultOptions.breakLength = Infinity;

//Detect our context, node/atom/browser
Expand Down Expand Up @@ -290,25 +290,34 @@ class InternalDebugLogger {
}

message_format(level, args) {

let level_color = "";
let level_str = "";
let prefix = "";
let msg;

if (args.length > 1) {
msg = util.format(...args);
} else {
msg = args[0] || '';
}

//Level coloring
let level_color = '\x1B[31m';
if (this._levels[level]) {
level_color = this._levels[level] === 1 ? '\x1B[33m' : '\x1B[36m';
}

//Level String
const level_str = level_color + `[${level}]`.padStart(7) + '\x1B[39m';

const proc = '[' + this._proc_name + '/' + this._pid + '] ';
const ftime = formatted_time();
const prefix = '\x1B[32m' + ftime + '\x1B[35m ' + proc;

//Level coloring and string
if (config.LOG_COLOR_ENABLED) {
level_color = '\x1B[31m';
if (this._levels[level]) {
level_color = this._levels[level] === 1 ? '\x1B[33m' : '\x1B[36m';
}
level_str = level_color + `[${level}]`.padStart(7) + '\x1B[39m';
prefix = '\x1B[32m' + ftime + '\x1B[35m ' + proc;
} else {
level_str = `[${level}]`.padStart(7);
prefix = ftime + proc;
}

msg = level_str + msg;
const msg_oneline = strip_newlines(msg);

Expand Down

0 comments on commit dd4e50a

Please sign in to comment.