updated loggers to getLogger

This commit is contained in:
Bojan Kucera 2025-06-08 19:52:11 -04:00
parent 1ccdbddb71
commit 2aaeba2f6c
16 changed files with 72 additions and 97 deletions

View file

@ -1,6 +1,6 @@
import { MongoClient, Db, Collection, MongoClientOptions, Document, WithId, OptionalUnlessRequiredId } from 'mongodb';
import { mongodbConfig } from '@stock-bot/config';
import { Logger } from '@stock-bot/logger';
import { getLogger } from '@stock-bot/logger';
import type {
MongoDBClientConfig,
MongoDBConnectionOptions,
@ -28,7 +28,7 @@ export class MongoDBClient {
private db: Db | null = null;
private readonly config: MongoDBClientConfig;
private readonly options: MongoDBConnectionOptions;
private readonly logger: Logger;
private readonly logger: ReturnType<typeof getLogger>;
private readonly healthMonitor: MongoDBHealthMonitor;
private isConnected = false;
@ -44,7 +44,7 @@ export class MongoDBClient {
...options
};
this.logger = new Logger('MongoDBClient');
this.logger = getLogger('mongodb-client');
this.healthMonitor = new MongoDBHealthMonitor(this);
}

View file

@ -1,4 +1,4 @@
import { Logger } from '@stock-bot/logger';
import { getLogger } from '@stock-bot/logger';
import type { MongoDBClient } from './client';
import type { MongoDBHealthCheck, MongoDBHealthStatus, MongoDBMetrics } from './types';
@ -9,14 +9,14 @@ import type { MongoDBHealthCheck, MongoDBHealthStatus, MongoDBMetrics } from './
*/
export class MongoDBHealthMonitor {
private readonly client: MongoDBClient;
private readonly logger: Logger;
private readonly logger: ReturnType<typeof getLogger>;
private healthCheckInterval: NodeJS.Timeout | null = null;
private metrics: MongoDBMetrics;
private lastHealthCheck: MongoDBHealthCheck | null = null;
constructor(client: MongoDBClient) {
this.client = client;
this.logger = new Logger('MongoDBHealthMonitor');
this.logger = getLogger('mongodb-health-monitor');
this.metrics = {
operationsPerSecond: 0,
averageLatency: 0,

View file

@ -1,4 +1,4 @@
import { Logger } from '@stock-bot/logger';
import { getLogger } from '@stock-bot/logger';
import type { MongoDBClient } from './client';
import type { CollectionNames, DocumentBase } from './types';
import type { WithId, OptionalUnlessRequiredId } from 'mongodb';
@ -10,11 +10,11 @@ import type { WithId, OptionalUnlessRequiredId } from 'mongodb';
*/
export class MongoDBTransactionManager {
private readonly client: MongoDBClient;
private readonly logger: Logger;
private readonly logger: ReturnType<typeof getLogger>;
constructor(client: MongoDBClient) {
this.client = client;
this.logger = new Logger('MongoDBTransactionManager');
this.logger = getLogger('mongodb-transaction-manager');
}
/**

View file

@ -1,6 +1,6 @@
import { Pool, PoolClient, QueryResult as PgQueryResult, QueryResultRow } from 'pg';
import { postgresConfig } from '@stock-bot/config';
import { Logger } from '@stock-bot/logger';
import { getLogger } from '@stock-bot/logger';
import type {
PostgreSQLClientConfig,
PostgreSQLConnectionOptions,
@ -21,7 +21,7 @@ export class PostgreSQLClient {
private pool: Pool | null = null;
private readonly config: PostgreSQLClientConfig;
private readonly options: PostgreSQLConnectionOptions;
private readonly logger: Logger;
private readonly logger: ReturnType<typeof getLogger>;
private readonly healthMonitor: PostgreSQLHealthMonitor;
private readonly transactionManager: PostgreSQLTransactionManager;
private isConnected = false;
@ -38,7 +38,7 @@ export class PostgreSQLClient {
...options
};
this.logger = new Logger('PostgreSQLClient');
this.logger = getLogger('postgres-client');
this.healthMonitor = new PostgreSQLHealthMonitor(this);
this.transactionManager = new PostgreSQLTransactionManager(this);
}

View file

@ -1,4 +1,4 @@
import { Logger } from '@stock-bot/logger';
import { getLogger } from '@stock-bot/logger';
import type { PostgreSQLClient } from './client';
import type { PostgreSQLHealthCheck, PostgreSQLHealthStatus, PostgreSQLMetrics } from './types';
@ -9,14 +9,14 @@ import type { PostgreSQLHealthCheck, PostgreSQLHealthStatus, PostgreSQLMetrics }
*/
export class PostgreSQLHealthMonitor {
private readonly client: PostgreSQLClient;
private readonly logger: Logger;
private readonly logger: ReturnType<typeof getLogger>;
private healthCheckInterval: NodeJS.Timeout | null = null;
private metrics: PostgreSQLMetrics;
private lastHealthCheck: PostgreSQLHealthCheck | null = null;
constructor(client: PostgreSQLClient) {
this.client = client;
this.logger = new Logger('PostgreSQLHealthMonitor');
this.logger = getLogger('postgres-health-monitor');
this.metrics = {
queriesPerSecond: 0,
averageQueryTime: 0,

View file

@ -1,5 +1,5 @@
import { PoolClient } from 'pg';
import { Logger } from '@stock-bot/logger';
import { getLogger } from '@stock-bot/logger';
import type { PostgreSQLClient } from './client';
import type { TransactionCallback } from './types';
@ -10,11 +10,11 @@ import type { TransactionCallback } from './types';
*/
export class PostgreSQLTransactionManager {
private readonly client: PostgreSQLClient;
private readonly logger: Logger;
private readonly logger: ReturnType<typeof getLogger>;
constructor(client: PostgreSQLClient) {
this.client = client;
this.logger = new Logger('PostgreSQLTransactionManager');
this.logger = getLogger('postgres-transaction-manager');
}
/**

View file

@ -1,4 +1,4 @@
import { Logger } from '@stock-bot/logger';
import { getLogger } from '@stock-bot/logger';
import type { HealthStatus, PerformanceMetrics, QueryResult } from './types';
// Interface to avoid circular dependency
@ -14,7 +14,7 @@ interface QuestDBClientInterface {
* automatic recovery capabilities for the QuestDB client.
*/
export class QuestDBHealthMonitor {
private readonly logger: Logger;
private readonly logger: ReturnType<typeof getLogger>;
private healthCheckInterval: NodeJS.Timeout | null = null;
private lastHealthCheck: Date | null = null;
private performanceMetrics: PerformanceMetrics = {
@ -27,7 +27,7 @@ export class QuestDBHealthMonitor {
memoryUsage: 0
};
constructor(private readonly client: QuestDBClientInterface) {
this.logger = new Logger('QuestDBHealthMonitor');
this.logger = getLogger('questdb-health-monitor');
}
/**

View file

@ -1,4 +1,4 @@
import { Logger } from '@stock-bot/logger';
import { getLogger } from '@stock-bot/logger';
import type {
InfluxLineData,
InfluxWriteOptions,
@ -17,7 +17,7 @@ interface QuestDBClientInterface {
* which QuestDB supports natively for optimal time-series data insertion.
*/
export class QuestDBInfluxWriter {
private readonly logger: Logger;
private readonly logger: ReturnType<typeof getLogger>;
private writeBuffer: string[] = [];
private flushTimer: NodeJS.Timeout | null = null;
private readonly defaultOptions: Required<InfluxWriteOptions> = {
@ -29,7 +29,7 @@ export class QuestDBInfluxWriter {
retryDelay: 1000
};
constructor(private readonly client: QuestDBClientInterface) {
this.logger = new Logger('QuestDBInfluxWriter');
this.logger = getLogger('questdb-influx-writer');
}
/**

View file

@ -1,4 +1,4 @@
import { Logger } from '@stock-bot/logger';
import { getLogger } from '@stock-bot/logger';
import type {
QueryResult,
TimeSeriesQuery,
@ -19,7 +19,7 @@ interface QuestDBClientInterface {
* with support for QuestDB-specific functions and optimizations.
*/
export class QuestDBQueryBuilder {
private readonly logger: Logger;
private readonly logger: ReturnType<typeof getLogger>;
private query!: {
select: string[];
from: string;
@ -32,7 +32,7 @@ export class QuestDBQueryBuilder {
timeRange?: TimeRange;
};
constructor(private readonly client: QuestDBClientInterface) {
this.logger = new Logger('QuestDBQueryBuilder');
this.logger = getLogger('questdb-query-builder');
this.reset();
}

View file

@ -1,4 +1,4 @@
import { Logger } from '@stock-bot/logger';
import { getLogger } from '@stock-bot/logger';
import type { TableSchema, IndexDefinition, TableNames, QueryResult } from './types';
// Interface to avoid circular dependency
@ -13,10 +13,10 @@ interface QuestDBClientInterface {
* for time-series data storage in QuestDB.
*/
export class QuestDBSchemaManager {
private readonly logger: Logger;
private readonly logger: ReturnType<typeof getLogger>;
private readonly schemas: Map<string, TableSchema> = new Map();
constructor(private readonly client: QuestDBClientInterface) {
this.logger = new Logger('QuestDBSchemaManager');
this.logger = getLogger('questdb-schema-manager');
this.initializeSchemas();
}