Tag indexing logs with document type

Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Eric Peterson
2022-10-10 18:02:33 +02:00
parent 0cc6914ae3
commit 8006f8a602
8 changed files with 20 additions and 9 deletions
@@ -112,13 +112,14 @@ export class IndexBuilder {
});
Object.keys(this.collators).forEach(type => {
const taskLogger = this.logger.child({ documentType: type });
scheduler.addToSchedule({
id: `search_index_${type.replace('-', '_').toLocaleLowerCase('en-US')}`,
scheduledRunner: this.collators[type].schedule,
task: async () => {
// Instantiate the collator.
const collator = await this.collators[type].factory.getCollator();
this.logger.info(
taskLogger.info(
`Collating documents for ${type} via ${this.collators[type].factory.constructor.name}`,
);
@@ -128,7 +129,7 @@ export class IndexBuilder {
.concat(this.decorators[type] || [])
.map(async factory => {
const decorator = await factory.getDecorator();
this.logger.info(
taskLogger.info(
`Attached decorator via ${factory.constructor.name} to ${type} index pipeline.`,
);
return decorator;
@@ -144,13 +145,13 @@ export class IndexBuilder {
[collator, ...decorators, indexer],
(error: NodeJS.ErrnoException | null) => {
if (error) {
this.logger.error(
taskLogger.error(
`Collating documents for ${type} failed: ${error}`,
);
reject(error);
} else {
// Signal index pipeline completion!
this.logger.info(`Collating documents for ${type} succeeded`);
taskLogger.info(`Collating documents for ${type} succeeded`);
resolve();
}
},
@@ -93,7 +93,7 @@ export class NewlineDelimitedJsonCollatorFactory
options.type,
options.searchPattern,
options.reader,
options.logger,
options.logger.child({ documentType: options.type }),
options.visibilityPermission,
);
}