diff --git a/packages/core-blockchain/src/blockchain.ts b/packages/core-blockchain/src/blockchain.ts index ab3d19c588..f1d10cc387 100644 --- a/packages/core-blockchain/src/blockchain.ts +++ b/packages/core-blockchain/src/blockchain.ts @@ -293,7 +293,8 @@ export class Blockchain implements blockchain.IBlockchain { while (this.state.getLastBlock().data.height >= newHeight + 1) { const removalBlockId = this.state.getLastBlock().data.id; const removalBlockHeight = this.state.getLastBlock().data.height.toLocaleString(); - logger.printTracker("Removing block", count++, max, `ID: ${removalBlockId}, height: ${removalBlockHeight}`); + + logger.info(`Removing block ${count++} of ${max} - ID: ${removalBlockId}, height: ${removalBlockHeight}`); await deleteLastBlock(); } @@ -301,7 +302,7 @@ export class Blockchain implements blockchain.IBlockchain { // Commit delete blocks await this.database.commitQueuedQueries(); - logger.stopTracker(`${pluralize("block", max, true)} removed`, count, max); + logger.info(`Removed ${count} ${pluralize("block", max, true)}`); await this.database.deleteRound(previousRound + 1); } @@ -316,10 +317,7 @@ export class Blockchain implements blockchain.IBlockchain { // If the current chain height is H and we will be removing blocks [N, H], // then blocksToRemove[] will contain blocks [N - 1, H - 1]. - const blocksToRemove = await this.database.getBlocks( - this.state.getLastBlock().data.height - nblocks, - nblocks, - ); + const blocksToRemove = await this.database.getBlocks(this.state.getLastBlock().data.height - nblocks, nblocks); const revertLastBlock = async () => { // tslint:disable-next-line:no-shadowed-variable diff --git a/packages/core-blockchain/src/utils/tick-sync-tracker.ts b/packages/core-blockchain/src/utils/tick-sync-tracker.ts index 712aa99028..ae104568ca 100644 --- a/packages/core-blockchain/src/utils/tick-sync-tracker.ts +++ b/packages/core-blockchain/src/utils/tick-sync-tracker.ts @@ -43,17 +43,10 @@ export function tickSyncTracker(blockCount, count) { secDecimalDigits: 0, }); - logger.printTracker( - "Fast Sync", - tracker.percent, - 100, - `(${blocksDownloaded} of ${networkHeight} blocks - Est. ${timeLeft})`, - ); + logger.info(`Synchronising In Progress (${blocksDownloaded} of ${networkHeight} blocks - Est. ${timeLeft})`); } if (tracker.percent === 100) { tracker = null; - - logger.stopTracker("Fast Sync", 100, 100); } } diff --git a/packages/core-database-postgres/src/spv.ts b/packages/core-database-postgres/src/spv.ts index d783389b86..8d165867dc 100644 --- a/packages/core-database-postgres/src/spv.ts +++ b/packages/core-database-postgres/src/spv.ts @@ -32,31 +32,30 @@ export class SPV { public async build(height) { this.activeDelegates = config.getMilestone(height).activeDelegates; - logger.printTracker("SPV", 1, 8, "Received Transactions"); + logger.info("SPV Step 1 of 8: Received Transactions"); await this.__buildReceivedTransactions(); - logger.printTracker("SPV", 2, 8, "Block Rewards"); + logger.info("SPV Step 2 of 8: Block Rewards"); await this.__buildBlockRewards(); - logger.printTracker("SPV", 3, 8, "Last Forged Blocks"); + logger.info("SPV Step 3 of 8: Last Forged Blocks"); await this.__buildLastForgedBlocks(); - logger.printTracker("SPV", 4, 8, "Sent Transactions"); + logger.info("SPV Step 4 of 8: Sent Transactions"); await this.__buildSentTransactions(); - logger.printTracker("SPV", 5, 8, "Second Signatures"); + logger.info("SPV Step 5 of 8: Second Signatures"); await this.__buildSecondSignatures(); - logger.printTracker("SPV", 6, 8, "Votes"); + logger.info("SPV Step 6 of 8: Votes"); await this.__buildVotes(); - logger.printTracker("SPV", 7, 8, "Delegates"); + logger.info("SPV Step 7 of 8: Delegates"); await this.__buildDelegates(); - logger.printTracker("SPV", 8, 8, "MultiSignatures"); + logger.info("SPV Step 8 of 8: MultiSignatures"); await this.__buildMultisignatures(); - logger.stopTracker("SPV", 8, 8); logger.info(`SPV rebuild finished, wallets in memory: ${Object.keys(this.walletManager.byAddress).length}`); logger.info(`Number of registered delegates: ${Object.keys(this.walletManager.byUsername).length}`); diff --git a/packages/core-interfaces/src/core-logger/logger.ts b/packages/core-interfaces/src/core-logger/logger.ts index 6132d17154..c01cbd5a8d 100644 --- a/packages/core-interfaces/src/core-logger/logger.ts +++ b/packages/core-interfaces/src/core-logger/logger.ts @@ -40,26 +40,6 @@ export interface ILogger { */ verbose(message: string): void; - /** - * Print the progress tracker. - * @param {String} title - * @param {Number} current - * @param {Number} max - * @param {String} postTitle - * @param {Number} figures - * @return {void} - */ - printTracker(title: string, current: number, max: number, postTitle?: string, figures?: number): void; - - /** - * Stop the progress tracker. - * @param {String} title - * @param {Number} current - * @param {Number} max - * @return {void} - */ - stopTracker(title: string, current: number, max: number): void; - /** * Suppress console output. * @param {Boolean} diff --git a/packages/core-logger-winston/__tests__/logger.test.ts b/packages/core-logger-winston/__tests__/logger.test.ts index bd4a25e3b6..ae1e64e0ab 100644 --- a/packages/core-logger-winston/__tests__/logger.test.ts +++ b/packages/core-logger-winston/__tests__/logger.test.ts @@ -82,31 +82,6 @@ describe("Logger", () => { }); }); - describe("printTracker", () => { - it("should print the tracker", () => { - logger.printTracker("test_title", 50, 100, "done"); - logger.printTracker("second_tracker", 0, 100, null); - - expect(message).toMatch(/test_title/); - expect(message).toMatch(/=========================/); - expect(message).toMatch(/50/); - expect(message).toMatch(/done/); - message = null; - }); - }); - - describe("stopTracker", () => { - it("should stop the tracker", () => { - logger.stopTracker("test_title", 50, 100); - logger.stopTracker("second_tracker", 101, 100); - - expect(message).toMatch(/test_title/); - expect(message).toMatch(/=========================/); - expect(message).toMatch(/100/); - message = null; - }); - }); - describe("suppressConsoleOutput", () => { it("should suppress console output", () => { logger.suppressConsoleOutput(true); diff --git a/packages/core-logger-winston/src/defaults.ts b/packages/core-logger-winston/src/defaults.ts index 4c2a482630..f8854266cf 100644 --- a/packages/core-logger-winston/src/defaults.ts +++ b/packages/core-logger-winston/src/defaults.ts @@ -6,7 +6,7 @@ export const defaults = { constructor: "Console", options: { level: process.env.CORE_LOG_LEVEL || "debug", - format: formatter(true, true), + format: formatter(true), stderrLevels: ["error", "warn"], }, }, @@ -15,7 +15,7 @@ export const defaults = { constructor: "DailyRotateFile", options: { level: process.env.CORE_LOG_LEVEL || "debug", - format: formatter(false, true), + format: formatter(false), filename: process.env.CORE_LOG_FILE || `${process.env.CORE_PATH_LOG}/%DATE%.log`, datePattern: "YYYY-MM-DD", zippedArchive: true, diff --git a/packages/core-logger-winston/src/driver.ts b/packages/core-logger-winston/src/driver.ts index faaa43f244..724770cb13 100644 --- a/packages/core-logger-winston/src/driver.ts +++ b/packages/core-logger-winston/src/driver.ts @@ -4,8 +4,6 @@ import isEmpty from "lodash/isEmpty"; import { inspect } from "util"; import * as winston from "winston"; -let tracker = null; - export class WinstonLogger extends AbstractLogger { public logger: any; @@ -69,64 +67,6 @@ export class WinstonLogger extends AbstractLogger { this.createLog("verbose", message); } - /** - * Print the progress tracker. - * @param {String} title - * @param {Number} current - * @param {Number} max - * @param {String} postTitle - * @param {Number} figures - * @return {void} - */ - public printTracker(title: string, current: number, max: number, postTitle?: string, figures?: number): void { - const progress = (100 * current) / max; - - let line = "\u{1b}[0G "; - line += title.blue; - line += " ["; - line += "=".repeat(Math.floor(progress / 2)).green; - line += `${" ".repeat(Math.ceil(50 - progress / 2))}] `; - line += `${progress.toFixed(figures || 0)}% `; - - if (postTitle) { - line += `${postTitle} `; - } - - process.stdout.write(line); - - tracker = line; - } - - /** - * Stop the progress tracker. - * @param {String} title - * @param {Number} current - * @param {Number} max - * @return {void} - */ - public stopTracker(title: string, current: number, max: number): void { - let progress = (100 * current) / max; - - if (progress > 100) { - progress = 100; - } - - let line = "\u{1b}[0G "; - line += title.blue; - line += " ["; - line += "=".repeat(progress / 2).green; - line += `${" ".repeat(50 - progress / 2)}] `; - line += `${progress.toFixed(0)}% `; - - if (progress === max) { - line += "✔️"; - } - - line += " \n"; - process.stdout.write(line); - tracker = null; - } - /** * Suppress console output. * @param {Boolean} diff --git a/packages/core-logger-winston/src/formatter.ts b/packages/core-logger-winston/src/formatter.ts index 4b2cdebc91..9249d5e04c 100644 --- a/packages/core-logger-winston/src/formatter.ts +++ b/packages/core-logger-winston/src/formatter.ts @@ -5,7 +5,7 @@ import { format } from "winston"; const { colorize, combine, timestamp, printf } = format; -const formatter = (colorOutput: boolean = true, makeReadable: boolean = true) => +const formatter = (colorOutput: boolean = true) => combine( colorize(), timestamp(), @@ -38,10 +38,7 @@ const formatter = (colorOutput: boolean = true, makeReadable: boolean = true) => const dateTime = dayjs(info.timestamp).format("YYYY-MM-DD HH:mm:ss"); - const dateTimeAndLevel = `[${dateTime}][${level}]:`; - const lineSpacer = makeReadable ? " ".repeat(Math.abs(dateTimeAndLevel.length - 50) + 1) : ""; - - return `[${dateTime}][${level}]${lineSpacer}: ${message}`; + return `[${dateTime}][${level}]: ${message}`; }), ); diff --git a/packages/core-logger/__tests__/__stubs__/logger.ts b/packages/core-logger/__tests__/__stubs__/logger.ts index 879e494684..0d9730c65c 100644 --- a/packages/core-logger/__tests__/__stubs__/logger.ts +++ b/packages/core-logger/__tests__/__stubs__/logger.ts @@ -25,14 +25,6 @@ export class Logger extends AbstractLogger { // } - public printTracker(title: string, current: number, max: number, postTitle: string, figures: number): void { - // - } - - public stopTracker(title: string, current: number, max: number): void { - // - } - public suppressConsoleOutput(suppress: boolean): void { // } diff --git a/packages/core-logger/src/logger.ts b/packages/core-logger/src/logger.ts index 9f81e8e55c..884c10be91 100644 --- a/packages/core-logger/src/logger.ts +++ b/packages/core-logger/src/logger.ts @@ -48,32 +48,6 @@ export abstract class AbstractLogger implements Logger.ILogger { */ public abstract verbose(message: any): void; - /** - * Print the progress tracker. - * @param {String} title - * @param {Number} current - * @param {Number} max - * @param {String} postTitle - * @param {Number} figures - * @return {void} - */ - public abstract printTracker( - title: string, - current: number, - max: number, - postTitle?: string, - figures?: number, - ): void; - - /** - * Stop the progress tracker. - * @param {String} title - * @param {Number} current - * @param {Number} max - * @return {void} - */ - public abstract stopTracker(title: string, current: number, max: number): void; - /** * Suppress console output. * @param {Boolean} diff --git a/packages/core-p2p/src/monitor.ts b/packages/core-p2p/src/monitor.ts index 3131c138f5..6e48b9ed8f 100644 --- a/packages/core-p2p/src/monitor.ts +++ b/packages/core-p2p/src/monitor.ts @@ -232,7 +232,6 @@ export class Monitor implements P2P.IMonitor { */ public async cleanPeers(fast = false, forcePing = false) { const keys = Object.keys(this.peers); - let count = 0; let unresponsivePeers = 0; const pingDelay = fast ? 1500 : localConfig.get("globalTimeout"); const max = keys.length; @@ -243,10 +242,6 @@ export class Monitor implements P2P.IMonitor { const peer = this.getPeer(ip); try { await peer.ping(pingDelay, forcePing); - - if (this.initializing) { - logger.printTracker("Peers Discovery", ++count, max); - } } catch (error) { unresponsivePeers++; @@ -262,7 +257,6 @@ export class Monitor implements P2P.IMonitor { ); if (this.initializing) { - logger.stopTracker("Peers Discovery", max, max); logger.info(`${max - unresponsivePeers} of ${max} peers on the network are responsive`); logger.info(`Median Network Height: ${this.getNetworkHeight().toLocaleString()}`); logger.info(`Network PBFT status: ${this.getPBFTForgingStatus()}`);