Skip to content

Commit 8b38064

Browse files
chore: use correct pluralization form in logs (#4321)
* chore(core-p2p): pluralize info logs * chore(core-p2p): pluralize debug logs * chore(core-blockchain): pluralize error logs * chore(core-blockchain): pluralize debug logs * chore(core-snapshots): pluralize logs * fix(core-p2p): fix log * fix: duplicated words in logs Co-authored-by: air1one <36802613+air1one@users.noreply.github.com>
1 parent 3fdb473 commit 8b38064

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

packages/core-blockchain/src/blockchain.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ export class Blockchain implements Contracts.Blockchain.Blockchain {
7777
const blocks = (job as ProcessBlocksJob).getBlocks();
7878

7979
this.logger.error(
80-
`Failed to process ${blocks.length.toLocaleString()} blocks from height ${blocks[0].height.toLocaleString()} in queue.`,
80+
`Failed to process ${Utils.pluralize(
81+
"block",
82+
blocks.length,
83+
true,
84+
)} from height ${blocks[0].height.toLocaleString()} in queue.`,
8185
);
8286
});
8387
}

packages/core-blockchain/src/process-blocks-job.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ export class ProcessBlocksJob implements Contracts.Kernel.QueueJob {
147147
await this.blockRepository.saveBlocks(acceptedBlocks);
148148
} catch (error) {
149149
this.logger.error(
150-
`Could not save ${acceptedBlocks.length.toLocaleString()} blocks to database : ${error.stack}`,
150+
`Could not save ${Utils.pluralize("block", acceptedBlocks.length, true)}) to database : ${
151+
error.stack
152+
}`,
151153
);
152154

153155
await this.revertBlocks(acceptedBlocks);

packages/core-blockchain/src/processor/handlers/unchained-handler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ export class UnchainedHandler implements BlockHandler {
127127
// NOTE: This isn't really elegant, but still better than spamming the log with
128128
// useless `not ready to accept` messages.
129129
if (this.blockchain.getQueue().size() > 0) {
130-
this.logger.debug(`Discarded ${this.blockchain.getQueue().size()} chunks of downloaded blocks.`);
130+
this.logger.debug(
131+
`Discarded ${Utils.pluralize(
132+
"chunk",
133+
this.blockchain.getQueue().size(),
134+
true,
135+
)} of downloaded blocks.`,
136+
);
131137
}
132138

133139
// If we consecutively fail to accept the same block, our chain is likely forked. In this

packages/core-p2p/src/network-monitor.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class NetworkMonitor implements Contracts.P2P.NetworkMonitor {
134134
max = Math.min(peers.length, peerCount);
135135
}
136136

137-
this.logger.info(`Checking ${max} peers`);
137+
this.logger.info(`Checking ${Utils.pluralize("peer", max, true)}`);
138138
const peerErrors = {};
139139

140140
// we use Promise.race to cut loose in case some communicator.ping() does not resolve within the delay
@@ -172,11 +172,13 @@ export class NetworkMonitor implements Contracts.P2P.NetworkMonitor {
172172

173173
for (const key of Object.keys(peerErrors)) {
174174
const peerCount = peerErrors[key].length;
175-
this.logger.debug(`Removed ${peerCount} ${Utils.pluralize("peer", peerCount)} because of "${key}"`);
175+
this.logger.debug(`Removed ${Utils.pluralize("peer", peerCount, true)} because of "${key}"`);
176176
}
177177

178178
if (this.initializing) {
179-
this.logger.info(`${max - unresponsivePeers} of ${max} peers on the network are responsive`);
179+
this.logger.info(
180+
`${max - unresponsivePeers} of ${Utils.pluralize("peer", max, true)} on the network are responsive`,
181+
);
180182
this.logger.info(`Median Network Height: ${this.getNetworkHeight().toLocaleString()}`);
181183
}
182184
}
@@ -263,7 +265,7 @@ export class NetworkMonitor implements Contracts.P2P.NetworkMonitor {
263265
}
264266

265267
public async refreshPeersAfterFork(): Promise<void> {
266-
this.logger.info(`Refreshing ${this.repository.getPeers().length} peers after fork.`);
268+
this.logger.info(`Refreshing ${Utils.pluralize("peer", this.repository.getPeers().length, true)} after fork.`);
267269

268270
await this.cleansePeers({ forcePing: true });
269271
}

packages/core-snapshots/src/database-service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ export class SnapshotDatabaseService implements Database.DatabaseService {
4949

5050
public async truncate(): Promise<void> {
5151
this.logger.info(
52-
`Clearing: ${await this.blockRepository.fastCount()} blocks, ${await this.transactionRepository.fastCount()} transactions, ${await this.roundRepository.fastCount()} rounds`,
52+
`Clearing: ${Utils.pluralize("block", await this.blockRepository.fastCount(), true)}, ${Utils.pluralize(
53+
"transaction",
54+
await this.transactionRepository.fastCount(),
55+
true,
56+
)}, ${Utils.pluralize("round", await this.roundRepository.fastCount(), true)}`,
5357
);
5458

5559
await this.blockRepository.truncate();
@@ -75,7 +79,11 @@ export class SnapshotDatabaseService implements Database.DatabaseService {
7579
const meta = this.prepareMetaData(options, dumpRage);
7680

7781
this.logger.info(
78-
`Start running dump for ${dumpRage.blocksCount} blocks, ${dumpRage.roundsCount} rounds and ${dumpRage.transactionsCount} transactions`,
82+
`Start running dump for ${Utils.pluralize("block", dumpRage.blocksCount, true)}, ${Utils.pluralize(
83+
"round",
84+
dumpRage.roundsCount,
85+
true,
86+
)} and ${Utils.pluralize("transaction", dumpRage.transactionsCount, true)}`,
7987
);
8088

8189
this.filesystem.setSnapshot(meta.folder);

packages/core-snapshots/src/snapshot-service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService {
5050
meta = await this.filesystem.readMetaData();
5151
} catch (e) {
5252
this.logger.error(
53-
`Metadata for snapshot ${options.blocks} of network ${options.network} is not valid.`,
53+
`Metadata for snapshot ${options.blocks} of network ${options.network} are not valid.`,
5454
);
5555
return;
5656
}
@@ -62,9 +62,11 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService {
6262
await this.database.restore(meta!, { truncate: !!options.truncate });
6363

6464
this.logger.info(
65-
`Successfully restore ${meta!.blocks.count.toLocaleString()} blocks, ${meta!.transactions.count.toLocaleString()} transactions, ${
66-
meta!.rounds.count
67-
} rounds`,
65+
`Successfully restore ${Utils.pluralize("block", meta!.blocks.count, true)}, ${Utils.pluralize(
66+
"transaction",
67+
meta!.transactions.count,
68+
true,
69+
)}, ${Utils.pluralize("round", meta!.rounds.count, true)}`,
6870
);
6971
} catch (err) {
7072
this.logger.error(`RESTORE failed.`);
@@ -90,7 +92,7 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService {
9092
meta = await this.filesystem.readMetaData();
9193
} catch (e) {
9294
this.logger.error(
93-
`Metadata for snapshot ${options.blocks} of network ${options.network} is not valid.`,
95+
`Metadata for snapshot ${options.blocks} of network ${options.network} are not valid.`,
9496
);
9597
}
9698

0 commit comments

Comments
 (0)