-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor utils modules before migrating to TS. (#3870)
- Loading branch information
Showing
4 changed files
with
217 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Oops, something went wrong.