Skip to content

Commit

Permalink
chore: use correct pluralization form in logs (#4321)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
sebastijankuzner and air1one authored Feb 16, 2021
1 parent 3fdb473 commit 8b38064
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
6 changes: 5 additions & 1 deletion packages/core-blockchain/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export class Blockchain implements Contracts.Blockchain.Blockchain {
const blocks = (job as ProcessBlocksJob).getBlocks();

this.logger.error(
`Failed to process ${blocks.length.toLocaleString()} blocks from height ${blocks[0].height.toLocaleString()} in queue.`,
`Failed to process ${Utils.pluralize(
"block",
blocks.length,
true,
)} from height ${blocks[0].height.toLocaleString()} in queue.`,
);
});
}
Expand Down
4 changes: 3 additions & 1 deletion packages/core-blockchain/src/process-blocks-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ export class ProcessBlocksJob implements Contracts.Kernel.QueueJob {
await this.blockRepository.saveBlocks(acceptedBlocks);
} catch (error) {
this.logger.error(
`Could not save ${acceptedBlocks.length.toLocaleString()} blocks to database : ${error.stack}`,
`Could not save ${Utils.pluralize("block", acceptedBlocks.length, true)}) to database : ${
error.stack
}`,
);

await this.revertBlocks(acceptedBlocks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ export class UnchainedHandler implements BlockHandler {
// NOTE: This isn't really elegant, but still better than spamming the log with
// useless `not ready to accept` messages.
if (this.blockchain.getQueue().size() > 0) {
this.logger.debug(`Discarded ${this.blockchain.getQueue().size()} chunks of downloaded blocks.`);
this.logger.debug(
`Discarded ${Utils.pluralize(
"chunk",
this.blockchain.getQueue().size(),
true,
)} of downloaded blocks.`,
);
}

// If we consecutively fail to accept the same block, our chain is likely forked. In this
Expand Down
10 changes: 6 additions & 4 deletions packages/core-p2p/src/network-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class NetworkMonitor implements Contracts.P2P.NetworkMonitor {
max = Math.min(peers.length, peerCount);
}

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

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

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

if (this.initializing) {
this.logger.info(`${max - unresponsivePeers} of ${max} peers on the network are responsive`);
this.logger.info(
`${max - unresponsivePeers} of ${Utils.pluralize("peer", max, true)} on the network are responsive`,
);
this.logger.info(`Median Network Height: ${this.getNetworkHeight().toLocaleString()}`);
}
}
Expand Down Expand Up @@ -263,7 +265,7 @@ export class NetworkMonitor implements Contracts.P2P.NetworkMonitor {
}

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

await this.cleansePeers({ forcePing: true });
}
Expand Down
12 changes: 10 additions & 2 deletions packages/core-snapshots/src/database-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export class SnapshotDatabaseService implements Database.DatabaseService {

public async truncate(): Promise<void> {
this.logger.info(
`Clearing: ${await this.blockRepository.fastCount()} blocks, ${await this.transactionRepository.fastCount()} transactions, ${await this.roundRepository.fastCount()} rounds`,
`Clearing: ${Utils.pluralize("block", await this.blockRepository.fastCount(), true)}, ${Utils.pluralize(
"transaction",
await this.transactionRepository.fastCount(),
true,
)}, ${Utils.pluralize("round", await this.roundRepository.fastCount(), true)}`,
);

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

this.logger.info(
`Start running dump for ${dumpRage.blocksCount} blocks, ${dumpRage.roundsCount} rounds and ${dumpRage.transactionsCount} transactions`,
`Start running dump for ${Utils.pluralize("block", dumpRage.blocksCount, true)}, ${Utils.pluralize(
"round",
dumpRage.roundsCount,
true,
)} and ${Utils.pluralize("transaction", dumpRage.transactionsCount, true)}`,
);

this.filesystem.setSnapshot(meta.folder);
Expand Down
12 changes: 7 additions & 5 deletions packages/core-snapshots/src/snapshot-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService {
meta = await this.filesystem.readMetaData();
} catch (e) {
this.logger.error(
`Metadata for snapshot ${options.blocks} of network ${options.network} is not valid.`,
`Metadata for snapshot ${options.blocks} of network ${options.network} are not valid.`,
);
return;
}
Expand All @@ -62,9 +62,11 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService {
await this.database.restore(meta!, { truncate: !!options.truncate });

this.logger.info(
`Successfully restore ${meta!.blocks.count.toLocaleString()} blocks, ${meta!.transactions.count.toLocaleString()} transactions, ${
meta!.rounds.count
} rounds`,
`Successfully restore ${Utils.pluralize("block", meta!.blocks.count, true)}, ${Utils.pluralize(
"transaction",
meta!.transactions.count,
true,
)}, ${Utils.pluralize("round", meta!.rounds.count, true)}`,
);
} catch (err) {
this.logger.error(`RESTORE failed.`);
Expand All @@ -90,7 +92,7 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService {
meta = await this.filesystem.readMetaData();
} catch (e) {
this.logger.error(
`Metadata for snapshot ${options.blocks} of network ${options.network} is not valid.`,
`Metadata for snapshot ${options.blocks} of network ${options.network} are not valid.`,
);
}

Expand Down

0 comments on commit 8b38064

Please sign in to comment.