Skip to content

Commit

Permalink
Refactor utils modules before migrating to TS. (#3870)
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 authored Aug 30, 2023
1 parent f60b34a commit 0822095
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 259 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"eslint:recommended"
],
"parserOptions": {
"ecmaVersion": 2020,
"ecmaVersion": 13,
"sourceType": "module",
"ecmaFeatures": {
"jsx": false
Expand Down
163 changes: 83 additions & 80 deletions lib/utils/logger/log_settings.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,106 @@
const lodashClone = require('lodash.clone');

const Settings = {
outputEnabled: true,
showResponseHeaders: false,
showRequestData: {
enabled: true,
trimLongScripts: true
},
detailedOutput: true,
disableErrorLog: false,
log_timestamp: false,
timestamp_format: null,
enabled: true
};

module.exports = new (function() {
const logSettings = lodashClone(Settings, true);

class LogSettings {
get outputEnabled() {
return logSettings.outputEnabled;
}

get detailedOutput() {
return logSettings.detailedOutput;
}
class LogSettings {
#outputEnabled;
#showResponseHeaders;
#showRequestData;
#detailedOutput;
#disableErrorLog;
#log_timestamp;
#timestamp_format;
#enabled;
#htmlReporterEnabled;

constructor() {
this.#outputEnabled = true;
this.#showResponseHeaders = false;
this.#showRequestData = {
enabled: true,
trimLongScripts: true
},
this.#detailedOutput = true;
this.#disableErrorLog = false;
this.#log_timestamp = false;
this.#timestamp_format = null;
this.#enabled = true;
this.#htmlReporterEnabled = false;
}

get showRequestData() {
return logSettings.showRequestData;
}
get outputEnabled() {
return this.#outputEnabled;
}

get enabled() {
return logSettings.enabled;
}
get detailedOutput() {
return this.#detailedOutput;
}

get showResponseHeaders() {
return logSettings.showResponseHeaders;
}
get showRequestData() {
return this.#showRequestData;
}

get timestampFormat() {
return logSettings.timestamp_format;
}
get enabled() {
return this.#enabled;
}

set outputEnabled(value) {
if (typeof value == 'undefined') {
value = true;
}
get showResponseHeaders() {
return this.#showResponseHeaders;
}

logSettings.outputEnabled = value;
}
get timestampFormat() {
return this.#timestamp_format;
}

set detailedOutput(value) {
logSettings.detailedOutput = value;
set outputEnabled(value) {
if (typeof value === 'undefined') {
value = true;
}

set disableErrorLog(value) {
if (typeof value == 'undefined') {
value = true;
}
this.#outputEnabled = value;
}

logSettings.disableErrorLog = value;
}
set detailedOutput(value) {
this.#detailedOutput = value;
}

set htmlReporterEnabled(value) {
logSettings.htmlReporterEnabled = value;
set disableErrorLog(value) {
if (typeof value === 'undefined') {
value = true;
}

get htmlReporterEnabled() {
return logSettings.htmlReporterEnabled;
}
this.#disableErrorLog = value;
}

isLogTimestamp() {
return logSettings.log_timestamp;
}
set htmlReporterEnabled(value) {
this.#htmlReporterEnabled = value;
}

isErrorLogEnabled() {
return !logSettings.disableErrorLog;
}
get htmlReporterEnabled() {
return this.#htmlReporterEnabled;
}

disable() {
logSettings.enabled = false;
}
isLogTimestamp() {
return this.#log_timestamp;
}

enable() {
logSettings.enabled = true;
}
isErrorLogEnabled() {
return !this.#disableErrorLog;
}

setLogTimestamp(val, format) {
logSettings.log_timestamp = val;
logSettings.timestamp_format = format;
}
disable() {
this.#enabled = false;
}

setHttpLogOptions({showRequestData, showResponseHeaders}) {
logSettings.showRequestData = showRequestData;
logSettings.showResponseHeaders = showResponseHeaders;
}
enable() {
this.#enabled = true;
}

setLogTimestamp(val, format) {
this.#log_timestamp = val;
this.#timestamp_format = format;
}

setHttpLogOptions({showRequestData, showResponseHeaders}) {
this.#showRequestData = showRequestData;
this.#showResponseHeaders = showResponseHeaders;
}
}

return new LogSettings();
})();
module.exports = new LogSettings();
Loading

0 comments on commit 0822095

Please sign in to comment.