updated loggers to getLogger
This commit is contained in:
parent
1ccdbddb71
commit
2aaeba2f6c
16 changed files with 72 additions and 97 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import { ProxyInfo } from 'libs/http/src/types';
|
||||
import { ProviderConfig } from '../services/provider-registry.service';
|
||||
import { Logger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
// Create logger for this provider
|
||||
const logger = new Logger('proxy-provider');
|
||||
const logger = getLogger('proxy-provider');
|
||||
|
||||
// This will run at the same time each day as when the app started
|
||||
const getEvery24HourCron = (): string => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Logger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import createCache, { type CacheProvider } from '@stock-bot/cache';
|
||||
import { HttpClient, ProxyInfo } from '@stock-bot/http';
|
||||
import pLimit from 'p-limit';
|
||||
|
|
@ -61,7 +61,7 @@ const PROXY_CONFIG = {
|
|||
};
|
||||
|
||||
// Shared instances (module-scoped, not global)
|
||||
let logger: Logger;
|
||||
let logger: ReturnType<typeof getLogger>;
|
||||
let cache: CacheProvider;
|
||||
let httpClient: HttpClient;
|
||||
let concurrencyLimit: ReturnType<typeof pLimit>;
|
||||
|
|
@ -69,7 +69,7 @@ let concurrencyLimit: ReturnType<typeof pLimit>;
|
|||
// Initialize shared resources
|
||||
function initializeSharedResources() {
|
||||
if (!logger) {
|
||||
logger = new Logger('proxy-tasks');
|
||||
logger = getLogger('proxy-tasks');
|
||||
cache = createCache('hybrid');
|
||||
httpClient = new HttpClient({ timeout: 10000 }, logger);
|
||||
concurrencyLimit = pLimit(PROXY_CONFIG.CONCURRENCY_LIMIT);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
import { ProviderConfig } from '../services/provider-registry.service';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
const logger = getLogger('quotemedia-provider');
|
||||
|
||||
export const quotemediaProvider: ProviderConfig = {
|
||||
name: 'quotemedia',
|
||||
service: 'market-data',
|
||||
operations: {
|
||||
'live-data': async (payload: { symbol: string; fields?: string[] }) => {
|
||||
const { Logger } = await import('@stock-bot/logger');
|
||||
const logger = new Logger('quotemedia-provider');
|
||||
|
||||
operations: { 'live-data': async (payload: { symbol: string; fields?: string[] }) => {
|
||||
logger.info('Fetching live data from QuoteMedia', { symbol: payload.symbol });
|
||||
|
||||
// Simulate QuoteMedia API call
|
||||
|
|
@ -33,12 +32,8 @@ export const quotemediaProvider: ProviderConfig = {
|
|||
from: Date;
|
||||
to: Date;
|
||||
interval?: string;
|
||||
fields?: string[];
|
||||
}) => {
|
||||
const { Logger } = await import('@stock-bot/logger');
|
||||
const logger = new Logger('quotemedia-provider');
|
||||
|
||||
logger.info('Fetching historical data from QuoteMedia', {
|
||||
fields?: string[]; }) => {
|
||||
logger.info('Fetching historical data from QuoteMedia', {
|
||||
symbol: payload.symbol,
|
||||
from: payload.from,
|
||||
to: payload.to,
|
||||
|
|
@ -73,12 +68,8 @@ export const quotemediaProvider: ProviderConfig = {
|
|||
totalRecords: data.length
|
||||
};
|
||||
},
|
||||
|
||||
'batch-quotes': async (payload: { symbols: string[]; fields?: string[] }) => {
|
||||
const { Logger } = await import('@stock-bot/logger');
|
||||
const logger = new Logger('quotemedia-provider');
|
||||
|
||||
logger.info('Fetching batch quotes from QuoteMedia', {
|
||||
'batch-quotes': async (payload: { symbols: string[]; fields?: string[] }) => {
|
||||
logger.info('Fetching batch quotes from QuoteMedia', {
|
||||
symbols: payload.symbols,
|
||||
count: payload.symbols.length
|
||||
});
|
||||
|
|
@ -101,12 +92,7 @@ export const quotemediaProvider: ProviderConfig = {
|
|||
timestamp: new Date().toISOString(),
|
||||
totalSymbols: payload.symbols.length
|
||||
};
|
||||
},
|
||||
|
||||
'company-profile': async (payload: { symbol: string }) => {
|
||||
const { Logger } = await import('@stock-bot/logger');
|
||||
const logger = new Logger('quotemedia-provider');
|
||||
|
||||
}, 'company-profile': async (payload: { symbol: string }) => {
|
||||
logger.info('Fetching company profile from QuoteMedia', { symbol: payload.symbol });
|
||||
|
||||
// Simulate company profile data
|
||||
|
|
@ -125,13 +111,8 @@ export const quotemediaProvider: ProviderConfig = {
|
|||
await new Promise(resolve => setTimeout(resolve, 150 + Math.random() * 100));
|
||||
|
||||
return profile;
|
||||
},
|
||||
|
||||
'options-chain': async (payload: { symbol: string; expiration?: string }) => {
|
||||
const { Logger } = await import('@stock-bot/logger');
|
||||
const logger = new Logger('quotemedia-provider');
|
||||
|
||||
logger.info('Fetching options chain from QuoteMedia', {
|
||||
}, 'options-chain': async (payload: { symbol: string; expiration?: string }) => {
|
||||
logger.info('Fetching options chain from QuoteMedia', {
|
||||
symbol: payload.symbol,
|
||||
expiration: payload.expiration
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import { ProviderConfig } from '../services/provider-registry.service';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
const logger = getLogger('yahoo-provider');
|
||||
|
||||
export const yahooProvider: ProviderConfig = {
|
||||
name: 'yahoo-finance',
|
||||
service: 'market-data',
|
||||
operations: {
|
||||
'live-data': async (payload: { symbol: string; modules?: string[] }) => {
|
||||
const { Logger } = await import('@stock-bot/logger');
|
||||
const logger = new Logger('yahoo-provider');
|
||||
|
||||
|
||||
logger.info('Fetching live data from Yahoo Finance', { symbol: payload.symbol });
|
||||
|
||||
|
|
@ -40,12 +42,11 @@ export const yahooProvider: ProviderConfig = {
|
|||
period1: number;
|
||||
period2: number;
|
||||
interval?: string;
|
||||
events?: string;
|
||||
}) => {
|
||||
const { Logger } = await import('@stock-bot/logger');
|
||||
const logger = new Logger('yahoo-provider');
|
||||
events?: string; }) => {
|
||||
const { getLogger } = await import('@stock-bot/logger');
|
||||
const logger = getLogger('yahoo-provider');
|
||||
|
||||
logger.info('Fetching historical data from Yahoo Finance', {
|
||||
logger.info('Fetching historical data from Yahoo Finance', {
|
||||
symbol: payload.symbol,
|
||||
period1: payload.period1,
|
||||
period2: payload.period2,
|
||||
|
|
@ -94,10 +95,9 @@ export const yahooProvider: ProviderConfig = {
|
|||
totalRecords: data.length
|
||||
};
|
||||
},
|
||||
|
||||
'search': async (payload: { query: string; quotesCount?: number; newsCount?: number }) => {
|
||||
const { Logger } = await import('@stock-bot/logger');
|
||||
const logger = new Logger('yahoo-provider');
|
||||
'search': async (payload: { query: string; quotesCount?: number; newsCount?: number }) => {
|
||||
const { getLogger } = await import('@stock-bot/logger');
|
||||
const logger = getLogger('yahoo-provider');
|
||||
|
||||
logger.info('Searching Yahoo Finance', { query: payload.query });
|
||||
|
||||
|
|
@ -129,13 +129,11 @@ export const yahooProvider: ProviderConfig = {
|
|||
totalNews: news.length,
|
||||
source: 'yahoo-finance'
|
||||
};
|
||||
},
|
||||
|
||||
'financials': async (payload: { symbol: string; type?: 'income' | 'balance' | 'cash' }) => {
|
||||
const { Logger } = await import('@stock-bot/logger');
|
||||
const logger = new Logger('yahoo-provider');
|
||||
}, 'financials': async (payload: { symbol: string; type?: 'income' | 'balance' | 'cash' }) => {
|
||||
const { getLogger } = await import('@stock-bot/logger');
|
||||
const logger = getLogger('yahoo-provider');
|
||||
|
||||
logger.info('Fetching financials from Yahoo Finance', {
|
||||
logger.info('Fetching financials from Yahoo Finance', {
|
||||
symbol: payload.symbol,
|
||||
type: payload.type || 'income'
|
||||
});
|
||||
|
|
@ -163,13 +161,11 @@ export const yahooProvider: ProviderConfig = {
|
|||
await new Promise(resolve => setTimeout(resolve, 300 + Math.random() * 200));
|
||||
|
||||
return financials;
|
||||
},
|
||||
|
||||
'earnings': async (payload: { symbol: string; period?: 'annual' | 'quarterly' }) => {
|
||||
const { Logger } = await import('@stock-bot/logger');
|
||||
const logger = new Logger('yahoo-provider');
|
||||
}, 'earnings': async (payload: { symbol: string; period?: 'annual' | 'quarterly' }) => {
|
||||
const { getLogger } = await import('@stock-bot/logger');
|
||||
const logger = getLogger('yahoo-provider');
|
||||
|
||||
logger.info('Fetching earnings from Yahoo Finance', {
|
||||
logger.info('Fetching earnings from Yahoo Finance', {
|
||||
symbol: payload.symbol,
|
||||
period: payload.period || 'quarterly'
|
||||
});
|
||||
|
|
@ -192,11 +188,9 @@ export const yahooProvider: ProviderConfig = {
|
|||
await new Promise(resolve => setTimeout(resolve, 250 + Math.random() * 150));
|
||||
|
||||
return earnings;
|
||||
},
|
||||
|
||||
'recommendations': async (payload: { symbol: string }) => {
|
||||
const { Logger } = await import('@stock-bot/logger');
|
||||
const logger = new Logger('yahoo-provider');
|
||||
}, 'recommendations': async (payload: { symbol: string }) => {
|
||||
const { getLogger } = await import('@stock-bot/logger');
|
||||
const logger = getLogger('yahoo-provider');
|
||||
|
||||
logger.info('Fetching recommendations from Yahoo Finance', { symbol: payload.symbol });
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Logger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
export interface JobHandler {
|
||||
(payload: any): Promise<any>;
|
||||
|
|
@ -22,7 +22,7 @@ export interface ProviderConfig {
|
|||
}
|
||||
|
||||
export class ProviderRegistry {
|
||||
private logger = new Logger('provider-registry');
|
||||
private logger = getLogger('provider-registry');
|
||||
private providers = new Map<string, ProviderConfig>();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Queue, Worker, QueueEvents } from 'bullmq';
|
||||
import { Logger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { providerRegistry } from './provider-registry.service';
|
||||
|
||||
export interface JobData {
|
||||
|
|
@ -13,7 +13,7 @@ export interface JobData {
|
|||
}
|
||||
|
||||
export class QueueService {
|
||||
private logger = new Logger('queue-service');
|
||||
private logger = getLogger('queue-service');
|
||||
private queue!: Queue;
|
||||
private workers: Worker[] = [];
|
||||
private queueEvents!: QueueEvents;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue