From 85408029b5ac9c0d21f415bc55e972d82c6c9167 Mon Sep 17 00:00:00 2001 From: mrfry Date: Tue, 7 Mar 2023 21:20:01 +0100 Subject: [PATCH] logger ability to disable all logs, rmduplicates logger disabling --- src/standaloneUtils/rmDuplicates.js | 6 ++++-- src/utils/logger.ts | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/standaloneUtils/rmDuplicates.js b/src/standaloneUtils/rmDuplicates.js index 6a1af18..5daf1d4 100644 --- a/src/standaloneUtils/rmDuplicates.js +++ b/src/standaloneUtils/rmDuplicates.js @@ -40,6 +40,7 @@ const logPath = './duplicateRemovingLog/' const globalLog = './duplicateRemovingLog/log' utils.CreatePath(logPath) utils.WriteFile('', globalLog) +logger.setLoggingDisabled(true) // ---------------------------------------------- let currentMaxIndex = -1 @@ -309,7 +310,8 @@ function difference({ dbA, dbB }) { for (let i = 0; i < dbA.length; i++) { const subj = dbA[i] - const subjLogPath = logPath + subj.Name + const subjLogPath = + logPath + (subj.Name || `EMPTY SUBJ ${new Date().getTime()}`) utils.WriteFile('', subjLogPath) let removedCount = 0 @@ -486,7 +488,7 @@ function printProgressBar(current, total) { for (let i = 0; i < xTotal - xCurrent; i++) { line += ' ' } - const numbers = `${current} / ${total}` + const numbers = `${current.toLocaleString()} / ${total.toLocaleString()}` writeInSameLine( `${C('magenta')} [${line}]${C('green')} ${numbers}${C()}`, current !== total diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 1620e16..4ea3a5d 100755 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -46,9 +46,14 @@ let dvData = {} // visit data, but daily let uvData = {} // visit data, but per user let udvData = {} // visit data, but per user and daily let writes = 0 +let loggingDisabled = false let noLogIds: string[] = [] +function setLoggingDisabled(newVal: boolean): void { + loggingDisabled = newVal +} + function getColoredDateString(): string { const date = new Date() const dateString = utils.GetDateString() @@ -81,7 +86,7 @@ function Log(msg: string | object, color?: string): void { log = getColoredDateString() + delimiter + C(color) + msg + C() } - if (!process.env.NS_NOLOG) { + if (!process.env.NS_NOLOG && !loggingDisabled) { console.log(log) } utils.AppendToFile( @@ -423,4 +428,5 @@ export default { logFileName: logFileName, logDir: logDir, vlogDir: vlogDir, + setLoggingDisabled: setLoggingDisabled, }