Skip to content

Commit

Permalink
Refactor: update log levels (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm committed Feb 22, 2024
1 parent 80811e7 commit 4d15f69
Show file tree
Hide file tree
Showing 26 changed files with 174 additions and 139 deletions.
9 changes: 9 additions & 0 deletions src/console/progressBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,29 @@ export default abstract class ProgressBar {

/**
* Log a TRACE message.
*
* This should be used to log internal actions that most users shouldn't care about, but could be
* helpful in bug reports.
*/
logTrace(message: string): void {
return this.log(LogLevel.TRACE, message);
}

/**
* Log a DEBUG message.
*
* This should be used to log actions that weren't taken (i.e. skipped writing a ROM because it
* already exists, etc.).
*/
logDebug(message: string): void {
return this.log(LogLevel.DEBUG, message);
}

/**
* Log an INFO message.
*
* This should be used to log actions that were taken (i.e. copying/moving ROMs, recycling files,
* writing DATs, etc.).
*/
logInfo(message: string): void {
return this.log(LogLevel.INFO, message);
Expand Down
4 changes: 2 additions & 2 deletions src/igir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class Igir {
const datsStatuses: DATStatus[] = [];

// Process every DAT
datProcessProgressBar.logInfo(`processing ${dats.length.toLocaleString()} DAT${dats.length !== 1 ? 's' : ''}`);
datProcessProgressBar.logTrace(`processing ${dats.length.toLocaleString()} DAT${dats.length !== 1 ? 's' : ''}`);
await async.eachLimit(dats, this.options.getDatThreads(), async (dat, callback) => {
await datProcessProgressBar.incrementProgress();

Expand Down Expand Up @@ -166,7 +166,7 @@ export default class Igir {
await datProcessProgressBar.incrementDone();
callback();
});
datProcessProgressBar.logInfo(`done processing ${dats.length.toLocaleString()} DAT${dats.length !== 1 ? 's' : ''}`);
datProcessProgressBar.logTrace(`done processing ${dats.length.toLocaleString()} DAT${dats.length !== 1 ? 's' : ''}`);

await datProcessProgressBar.doneItems(dats.length, 'DAT', 'processed');
datProcessProgressBar.delete();
Expand Down
4 changes: 2 additions & 2 deletions src/modules/argumentsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class ArgumentsParser {
* Parse the arguments.
*/
parse(argv: string[]): Options {
this.logger.info(`Parsing CLI arguments: ${argv}`);
this.logger.trace(`Parsing CLI arguments: ${argv}`);

const groupInput = 'Input options (supports globbing):';
const groupDatInput = 'DAT input options:';
Expand Down Expand Up @@ -816,7 +816,7 @@ Example use cases:
});

const options = Options.fromObject(yargsArgv);
this.logger.info(`Parsed options: ${options.toString()}`);
this.logger.trace(`Parsed options: ${options.toString()}`);

return options;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/candidateCombiner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export default class CandidateCombiner extends Module {
}

if (parentsToCandidates.size === 0) {
this.progressBar.logDebug(`${dat.getNameShort()}: no parents to make patched candidates for`);
this.progressBar.logTrace(`${dat.getNameShort()}: no parents to make patched candidates for`);
return parentsToCandidates;
}

this.progressBar.logInfo(`${dat.getNameShort()}: generating consolidated candidate`);
this.progressBar.logTrace(`${dat.getNameShort()}: generating consolidated candidate`);
await this.progressBar.setSymbol(ProgressBarSymbol.COMBINING_ALL);
await this.progressBar.reset(parentsToCandidates.size);

Expand Down
12 changes: 6 additions & 6 deletions src/modules/candidateGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export default class CandidateGenerator extends Module {
hashCodeToInputFiles: Map<string, File[]>,
): Promise<Map<Parent, ReleaseCandidate[]>> {
if (hashCodeToInputFiles.size === 0) {
this.progressBar.logDebug(`${dat.getNameShort()}: no input ROMs to make candidates from`);
this.progressBar.logTrace(`${dat.getNameShort()}: no input ROMs to make candidates from`);
return new Map();
}

const output = new Map<Parent, ReleaseCandidate[]>();
const parents = dat.getParents();

this.progressBar.logInfo(`${dat.getNameShort()}: generating candidates`);
this.progressBar.logTrace(`${dat.getNameShort()}: generating candidates`);
await this.progressBar.setSymbol(ProgressBarSymbol.GENERATING);
await this.progressBar.reset(parents.length);

Expand Down Expand Up @@ -90,9 +90,9 @@ export default class CandidateGenerator extends Module {
.flatMap((releaseCandidate) => releaseCandidate.getRomsWithFiles())
.reduce((sum, romWithFiles) => sum + romWithFiles.getRom().getSize(), 0);
const totalCandidates = [...output.values()].reduce((sum, rc) => sum + rc.length, 0);
this.progressBar.logDebug(`${dat.getNameShort()}: generated ${fsPoly.sizeReadable(size)} of ${totalCandidates.toLocaleString()} candidate${totalCandidates !== 1 ? 's' : ''} for ${output.size.toLocaleString()} parent${output.size !== 1 ? 's' : ''}`);
this.progressBar.logTrace(`${dat.getNameShort()}: generated ${fsPoly.sizeReadable(size)} of ${totalCandidates.toLocaleString()} candidate${totalCandidates !== 1 ? 's' : ''} for ${output.size.toLocaleString()} parent${output.size !== 1 ? 's' : ''}`);

this.progressBar.logInfo(`${dat.getNameShort()}: done generating candidates`);
this.progressBar.logTrace(`${dat.getNameShort()}: done generating candidates`);
return output;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ export default class CandidateGenerator extends Module {
const romWithFiles = new ROMWithFiles(rom, finalInputFile, outputFile);
return [rom, romWithFiles];
} catch (error) {
this.progressBar.logInfo(`${dat.getNameShort()}: ${game.getName()}: ${error}`);
this.progressBar.logWarn(`${dat.getNameShort()}: ${game.getName()}: ${error}`);
return [rom, undefined];
}
}),
Expand Down Expand Up @@ -308,7 +308,7 @@ export default class CandidateGenerator extends Module {
missingRoms.forEach((rom) => {
message += `\n ${rom.getName()}`;
});
this.progressBar.logDebug(message);
this.progressBar.logTrace(message);
}

private hasConflictingOutputFiles(romsWithFiles: ROMWithFiles[]): boolean {
Expand Down
6 changes: 3 additions & 3 deletions src/modules/candidateMergeSplitValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class CandidateMergeSplitValidator extends Module {
dat: DAT,
parentsToCandidates: Map<Parent, ReleaseCandidate[]>,
): Promise<void> {
this.progressBar.logInfo(`${dat.getNameShort()}: validating merged & split ROM sets`);
this.progressBar.logTrace(`${dat.getNameShort()}: validating merged & split ROM sets`);

await this.progressBar.setSymbol(ProgressBarSymbol.VALIDATING);
await this.progressBar.reset(parentsToCandidates.size);
Expand Down Expand Up @@ -87,10 +87,10 @@ export default class CandidateMergeSplitValidator extends Module {
}

if (missingDependencies.length > 0) {
this.progressBar.logWarn(`${game.getName()}: missing dependent ROM set${missingDependencies.length !== 1 ? 's' : ''}: ${missingDependencies.join(', ')}`);
this.progressBar.logWarn(`${dat.getNameShort()}: ${game.getName()}: missing dependent ROM set${missingDependencies.length !== 1 ? 's' : ''}: ${missingDependencies.join(', ')}`);
}
});

this.progressBar.logInfo(`${dat.getNameShort()}: done validating merged & split ROM sets`);
this.progressBar.logTrace(`${dat.getNameShort()}: done validating merged & split ROM sets`);
}
}
10 changes: 5 additions & 5 deletions src/modules/candidatePatchGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ export default class CandidatePatchGenerator extends Module {
patches: Patch[],
): Promise<Map<Parent, ReleaseCandidate[]>> {
if (parentsToCandidates.size === 0) {
this.progressBar.logDebug(`${dat.getNameShort()}: no parents to make patched candidates for`);
this.progressBar.logTrace(`${dat.getNameShort()}: no parents to make patched candidates for`);
return parentsToCandidates;
}

this.progressBar.logInfo(`${dat.getNameShort()}: generating patched candidates`);
this.progressBar.logTrace(`${dat.getNameShort()}: generating patched candidates`);
await this.progressBar.setSymbol(ProgressBarSymbol.GENERATING);
await this.progressBar.reset(parentsToCandidates.size);

const crcToPatches = CandidatePatchGenerator.indexPatchesByCrcBefore(patches);
this.progressBar.logDebug(`${dat.getNameShort()}: ${crcToPatches.size} unique patches found`);
this.progressBar.logTrace(`${dat.getNameShort()}: ${crcToPatches.size} unique patch${crcToPatches.size !== 1 ? 'es' : ''} found`);

const patchedParentsToCandidates = this.build(dat, parentsToCandidates, crcToPatches);
this.progressBar.logInfo(`${dat.getNameShort()}: done generating patched candidates`);
this.progressBar.logTrace(`${dat.getNameShort()}: done generating patched candidates`);

return patchedParentsToCandidates;
}
Expand Down Expand Up @@ -117,7 +117,7 @@ export default class CandidatePatchGenerator extends Module {
.flat()
.filter((patch) => !usedPatches.has(patch.getFile().toString()))
.forEach((patch) => {
this.progressBar.logWarn(`no matching input file found for patch: ${patch.getFile().toString()}`);
this.progressBar.logWarn(`${patch.getFile().toString()}: no matching input file found for patch`);
});

return patchedParentsToCandidates;
Expand Down
6 changes: 3 additions & 3 deletions src/modules/candidatePostProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export default class CandidatePostProcessor extends Module {
parentsToCandidates: Map<Parent, ReleaseCandidate[]>,
): Promise<Map<Parent, ReleaseCandidate[]>> {
if (parentsToCandidates.size === 0) {
this.progressBar.logDebug(`${dat.getNameShort()}: no parents, so no candidates to process`);
this.progressBar.logTrace(`${dat.getNameShort()}: no parents, so no candidates to process`);
return parentsToCandidates;
}

this.progressBar.logInfo(`${dat.getNameShort()}: processing candidates`);
this.progressBar.logTrace(`${dat.getNameShort()}: processing candidates`);
await this.progressBar.setSymbol(ProgressBarSymbol.GENERATING);
await this.progressBar.reset(parentsToCandidates.size);

Expand Down Expand Up @@ -64,7 +64,7 @@ export default class CandidatePostProcessor extends Module {
return [parent, newReleaseCandidates];
}));

this.progressBar.logInfo(`${dat.getNameShort()}: done processing candidates`);
this.progressBar.logTrace(`${dat.getNameShort()}: done processing candidates`);
return processedCandidates;
}

Expand Down
12 changes: 6 additions & 6 deletions src/modules/candidatePreferer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ export default class CandidatePreferer extends Module {
dat: DAT,
parentsToCandidates: Map<Parent, ReleaseCandidate[]>,
): Promise<Map<Parent, ReleaseCandidate[]>> {
this.progressBar.logInfo(`${dat.getNameShort()}: preferring candidates`);
this.progressBar.logTrace(`${dat.getNameShort()}: preferring candidates`);

if (parentsToCandidates.size === 0) {
this.progressBar.logDebug(`${dat.getNameShort()}: no parents, so no candidates to prefer`);
this.progressBar.logTrace(`${dat.getNameShort()}: no parents, so no candidates to prefer`);
return parentsToCandidates;
}

if (!this.options.getSingle()) {
this.progressBar.logDebug(`${dat.getNameShort()}: not running in single/1G1R mode, not preferring candidates`);
this.progressBar.logTrace(`${dat.getNameShort()}: not running in single/1G1R mode, not preferring candidates`);
return parentsToCandidates;
}

// Return early if there aren't any candidates
const totalReleaseCandidates = [...parentsToCandidates.values()]
.reduce((sum, rcs) => sum + rcs.length, 0);
if (!totalReleaseCandidates) {
this.progressBar.logDebug(`${dat.getNameShort()}: no parent has candidates`);
this.progressBar.logTrace(`${dat.getNameShort()}: no parent has candidates`);
return parentsToCandidates;
}

Expand All @@ -57,9 +57,9 @@ export default class CandidatePreferer extends Module {
.flatMap((releaseCandidate) => releaseCandidate.getRomsWithFiles())
.reduce((sum, romWithFiles) => sum + romWithFiles.getRom().getSize(), 0);
const filteredCandidates = [...output.values()].reduce((sum, rc) => sum + rc.length, 0);
this.progressBar.logDebug(`${dat.getNameShort()}: filtered to ${fsPoly.sizeReadable(size)} of ${filteredCandidates.toLocaleString()} candidate${filteredCandidates !== 1 ? 's' : ''} for ${output.size.toLocaleString()} parent${output.size !== 1 ? 's' : ''}`);
this.progressBar.logTrace(`${dat.getNameShort()}: filtered to ${fsPoly.sizeReadable(size)} of ${filteredCandidates.toLocaleString()} candidate${filteredCandidates !== 1 ? 's' : ''} for ${output.size.toLocaleString()} parent${output.size !== 1 ? 's' : ''}`);

this.progressBar.logInfo(`${dat.getNameShort()}: done preferring candidates`);
this.progressBar.logTrace(`${dat.getNameShort()}: done preferring candidates`);
return output;
}

Expand Down
Loading

0 comments on commit 4d15f69

Please sign in to comment.