Skip to content

Commit 66a2d63

Browse files
committed
feat: analysis에 logger 메시지 추가
1 parent 086ea51 commit 66a2d63

5 files changed

Lines changed: 26 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "document-dataply",
3-
"version": "0.0.14-alpha.3",
3+
"version": "0.0.14-alpha.4",
44
"description": "Simple and powerful JSON document database supporting complex queries and flexible indexing policies.",
55
"license": "MIT",
66
"author": "izure <admin@izure.org>",

src/core/AnalysisManager.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
import type { DocumentDataplyAPI } from './documentAPI'
77
import type { AnalysisProvider } from './AnalysisProvider'
88
import { Cron } from 'croner'
9-
import { Transaction, Logger } from 'dataply'
9+
import { Transaction, Logger, LoggerManager } from 'dataply'
1010
import { RealtimeAnalysisProvider } from './RealtimeAnalysisProvider'
1111
import { IntervalAnalysisProvider } from './IntervalAnalysisProvider'
1212
import { BuiltinAnalysisProviders } from './analysis'
@@ -16,15 +16,20 @@ export class AnalysisManager<T extends DocumentJSON> {
1616
private cron: Cron | null = null
1717
private flushing: boolean = false
1818

19+
private logger: Logger
20+
1921
constructor(
2022
private api: DocumentDataplyAPI<T>,
2123
schedule: string,
2224
public readonly sampleSize: number,
23-
private logger: Logger
25+
private loggerManager: LoggerManager
2426
) {
27+
this.logger = loggerManager.create('document-dataply:analysis')
2528
this.cron = new Cron(schedule, async () => {
2629
if (this.flushing) return
2730
await this.api.flushAnalysis()
31+
}, {
32+
paused: true
2833
})
2934
}
3035

@@ -44,7 +49,7 @@ export class AnalysisManager<T extends DocumentJSON> {
4449
*/
4550
registerBuiltinProviders(): void {
4651
for (const Provider of BuiltinAnalysisProviders) {
47-
const instance = new Provider(this.api)
52+
const instance = new Provider(this.api, this.loggerManager)
4853
this.registerProvider(instance)
4954
}
5055
}

src/core/AnalysisProvider.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DocumentJSON } from '../types'
22
import type { DocumentDataplyAPI } from './documentAPI'
3-
import type { Transaction } from 'dataply'
3+
import type { Transaction, Logger, LoggerManager } from 'dataply'
44

55
/**
66
* Abstract base class for analysis providers.
@@ -10,7 +10,15 @@ export abstract class AnalysisProvider<T extends DocumentJSON = DocumentJSON> {
1010
/** Overflow row PK assigned by AnalysisManager during initialization. */
1111
storageKey: number = -1
1212

13-
constructor(protected api: DocumentDataplyAPI<T>) { }
13+
private _logger?: Logger
14+
protected get logger(): Logger {
15+
if (!this._logger) {
16+
this._logger = this.loggerManager.create(`document-dataply:analysis:${this.name}`)
17+
}
18+
return this._logger
19+
}
20+
21+
constructor(protected api: DocumentDataplyAPI<T>, protected loggerManager: LoggerManager) { }
1422

1523
/**
1624
* Unique name of this analysis type (e.g. 'ftsTermCount').

src/core/analysis/FTSTermCount.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class FTSTermCount<T extends DocumentJSON = DocumentJSON> extends Interva
1313
private sampleSize: number = 0
1414

1515
async serialize(tx: Transaction): Promise<string> {
16+
this.logger.debug(`Starting serialize`)
1617
const docs = await this.sample({ count: this.api.analysisManager.sampleSize }, tx)
1718

1819
this.termCount = {}
@@ -78,13 +79,16 @@ export class FTSTermCount<T extends DocumentJSON = DocumentJSON> extends Interva
7879

7980
this.termCount = optimizedTermCount
8081

82+
this.logger.debug(`Serialize complete, sampleSize: ${this.sampleSize}`)
8183
return JSON.stringify({ _sampleSize: this.sampleSize, ...this.termCount })
8284
}
8385

8486
async load(data: string | null, tx: Transaction): Promise<void> {
87+
this.logger.debug(`Loading data`)
8588
this.termCount = {}
8689
this.sampleSize = 0
8790
if (!data) {
91+
this.logger.debug(`No existing data found, initialized as empty`)
8892
return
8993
}
9094
try {
@@ -94,7 +98,9 @@ export class FTSTermCount<T extends DocumentJSON = DocumentJSON> extends Interva
9498
this.sampleSize = typeof _sampleSize === 'number' ? _sampleSize : 0
9599
this.termCount = rest
96100
}
101+
this.logger.debug(`Successfully parsed existing data (sampleSize: ${this.sampleSize})`)
97102
} catch (e) {
103+
this.logger.warn(`Failed to parse existing data`, e)
98104
// Ignore parse error
99105
}
100106
}

src/core/documentAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyAPI {
4747
this,
4848
options.analysisSchedule ?? '* */1 * * *',
4949
options.analysisSampleSize ?? 1000,
50-
this.loggerManager.create('document-dataply:analysis')
50+
this.loggerManager
5151
)
5252

5353
this.hook.onceAfter('close', async () => {

0 commit comments

Comments
 (0)