removed deprecated createLogger and replaced with getLogger
This commit is contained in:
parent
5d8b102422
commit
c10a524aa8
29 changed files with 93 additions and 136 deletions
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Data Service - Combined live and historical data ingestion
|
||||
*/
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { loadEnvVariables } from '@stock-bot/config';
|
||||
import { Hono } from 'hono';
|
||||
import { serve } from '@hono/node-server';
|
||||
|
|
@ -10,7 +10,7 @@ import { serve } from '@hono/node-server';
|
|||
loadEnvVariables();
|
||||
|
||||
const app = new Hono();
|
||||
const logger = createLogger('data-service');
|
||||
const logger = getLogger('data-service');
|
||||
|
||||
const PORT = parseInt(process.env.DATA_SERVICE_PORT || '3002');
|
||||
// Health check endpoint
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/**
|
||||
* Unified data interface for live and historical data
|
||||
*/
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { QuestDBClient } from '@stock-bot/questdb-client';
|
||||
import { EventBus } from '@stock-bot/event-bus';
|
||||
|
||||
const logger = createLogger('unified-data-provider');
|
||||
const logger = getLogger('unified-data-provider');
|
||||
|
||||
export interface MarketData {
|
||||
symbol: string;
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ export class ProxyService {
|
|||
private logger = new Logger('proxy-service');
|
||||
private cache: CacheProvider = createCache('hybrid');
|
||||
private httpClient: HttpClient;
|
||||
private readonly concurrencyLimit = pLimit(200);
|
||||
private readonly concurrencyLimit = pLimit(250);
|
||||
private readonly CACHE_KEY = 'proxy';
|
||||
private readonly CACHE_TTL = 86400; // 24 hours
|
||||
private readonly CHECK_TIMEOUT = 7000;
|
||||
private readonly CHECK_TIMEOUT = 5000;
|
||||
private readonly CHECK_IP = '99.246.102.205'
|
||||
private readonly CHECK_URL = 'https://proxy-detection.stare.gg/?api_key=bd406bf53ddc6abe1d9de5907830a955';
|
||||
private readonly PROXY_SOURCES = [
|
||||
|
|
@ -164,7 +164,7 @@ export class ProxyService {
|
|||
*/
|
||||
async checkProxy(proxy: ProxyInfo): Promise<ProxyInfo> {
|
||||
let success = false;
|
||||
this.logger.debug('Checking Proxy : ', {
|
||||
this.logger.debug(`Checking Proxy with ${this.concurrencyLimit.pendingCount } pending: `, {
|
||||
protocol: proxy.protocol,
|
||||
host: proxy.host,
|
||||
port: proxy.port,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Order } from '@stock-bot/types';
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
export interface RiskRule {
|
||||
name: string;
|
||||
|
|
@ -21,7 +21,7 @@ export interface RiskValidationResult {
|
|||
}
|
||||
|
||||
export class RiskManager {
|
||||
private logger = createLogger('risk-manager');
|
||||
private logger = getLogger('risk-manager');
|
||||
private rules: RiskRule[] = [];
|
||||
|
||||
constructor() {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { Hono } from 'hono';
|
||||
import { serve } from '@hono/node-server';
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { config } from '@stock-bot/config';
|
||||
// import { BrokerInterface } from './broker/interface.ts';
|
||||
// import { OrderManager } from './execution/order-manager.ts';
|
||||
// import { RiskManager } from './execution/risk-manager.ts';
|
||||
|
||||
const app = new Hono();
|
||||
const logger = createLogger('execution-service');
|
||||
const logger = getLogger('execution-service');
|
||||
// Health check endpoint
|
||||
app.get('/health', (c) => {
|
||||
return c.json({
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { Hono } from 'hono';
|
||||
import { serve } from '@hono/node-server';
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { config } from '@stock-bot/config';
|
||||
import { PortfolioManager } from './portfolio/portfolio-manager.ts';
|
||||
import { PerformanceAnalyzer } from './analytics/performance-analyzer.ts';
|
||||
|
||||
const app = new Hono();
|
||||
const logger = createLogger('portfolio-service');
|
||||
const logger = getLogger('portfolio-service');
|
||||
// Health check endpoint
|
||||
app.get('/health', (c) => {
|
||||
return c.json({
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
export interface Position {
|
||||
symbol: string;
|
||||
|
|
@ -34,7 +34,7 @@ export interface Trade {
|
|||
}
|
||||
|
||||
export class PortfolioManager {
|
||||
private logger = createLogger('PortfolioManager');
|
||||
private logger = getLogger('PortfolioManager');
|
||||
private positions: Map<string, Position> = new Map();
|
||||
private trades: Trade[] = [];
|
||||
private cashBalance: number = 100000; // Starting cash
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Processing Service - Technical indicators and data processing
|
||||
*/
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { loadEnvVariables } from '@stock-bot/config';
|
||||
import { Hono } from 'hono';
|
||||
import { serve } from '@hono/node-server';
|
||||
|
|
@ -10,7 +10,7 @@ import { serve } from '@hono/node-server';
|
|||
loadEnvVariables();
|
||||
|
||||
const app = new Hono();
|
||||
const logger = createLogger('processing-service');
|
||||
const logger = getLogger('processing-service');
|
||||
const PORT = parseInt(process.env.PROCESSING_SERVICE_PORT || '3003');
|
||||
|
||||
// Health check endpoint
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
* Technical Indicators Service
|
||||
* Leverages @stock-bot/utils for calculations
|
||||
*/
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import {
|
||||
sma,
|
||||
ema,
|
||||
|
|
@ -10,7 +10,7 @@ import {
|
|||
macd
|
||||
} from '@stock-bot/utils';
|
||||
|
||||
const logger = createLogger('indicators-service');
|
||||
const logger = getLogger('indicators-service');
|
||||
|
||||
export interface IndicatorRequest {
|
||||
symbol: string;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { EventBus } from '@stock-bot/event-bus';
|
||||
import { VectorEngine, VectorizedBacktestResult } from '@stock-bot/vector-engine';
|
||||
import { DataFrame } from '@stock-bot/data-frame';
|
||||
|
|
@ -43,7 +43,7 @@ export class HybridMode extends ExecutionMode {
|
|||
this.eventMode = new EventMode(context, eventBus);
|
||||
this.vectorizedMode = new VectorizedMode(context, eventBus);
|
||||
|
||||
this.logger = createLogger('hybrid-mode');
|
||||
this.logger = getLogger('hybrid-mode');
|
||||
}
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { EventBus } from '@stock-bot/event-bus';
|
||||
import { VectorEngine, VectorizedBacktestResult } from '@stock-bot/vector-engine';
|
||||
import { DataFrame } from '@stock-bot/data-frame';
|
||||
|
|
@ -13,7 +13,7 @@ export interface VectorizedModeConfig {
|
|||
export class VectorizedMode extends ExecutionMode {
|
||||
private vectorEngine: VectorEngine;
|
||||
private config: VectorizedModeConfig;
|
||||
private logger = createLogger('vectorized-mode');
|
||||
private logger = getLogger('vectorized-mode');
|
||||
|
||||
constructor(
|
||||
context: BacktestContext,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { program } from 'commander';
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { createEventBus } from '@stock-bot/event-bus';
|
||||
import { BacktestContext } from '../framework/execution-mode';
|
||||
import { LiveMode } from '../backtesting/modes/live-mode';
|
||||
|
|
@ -13,7 +13,7 @@ import { EventMode } from '../backtesting/modes/event-mode';
|
|||
import VectorizedMode from '../backtesting/modes/vectorized-mode';
|
||||
import HybridMode from '../backtesting/modes/hybrid-mode';
|
||||
|
||||
const logger = createLogger('strategy-cli');
|
||||
const logger = getLogger('strategy-cli');
|
||||
|
||||
interface CLIBacktestConfig {
|
||||
strategy: string;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
* Execution Mode Framework
|
||||
* Base classes for different execution modes (live, event-driven, vectorized)
|
||||
*/
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
const logger = createLogger('execution-mode');
|
||||
const logger = getLogger('execution-mode');
|
||||
|
||||
export interface Order {
|
||||
id: string;
|
||||
|
|
@ -38,7 +38,7 @@ export interface MarketData {
|
|||
}
|
||||
|
||||
export abstract class ExecutionMode {
|
||||
protected logger = createLogger(this.constructor.name);
|
||||
protected logger = getLogger(this.constructor.name);
|
||||
|
||||
abstract name: string;
|
||||
abstract executeOrder(order: Order): Promise<OrderResult>;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Strategy Service - Multi-mode strategy execution and backtesting
|
||||
*/
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { loadEnvVariables } from '@stock-bot/config';
|
||||
import { Hono } from 'hono';
|
||||
import { serve } from '@hono/node-server';
|
||||
|
|
@ -10,7 +10,7 @@ import { serve } from '@hono/node-server';
|
|||
loadEnvVariables();
|
||||
|
||||
const app = new Hono();
|
||||
const logger = createLogger('strategy-service');
|
||||
const logger = getLogger('strategy-service');
|
||||
const PORT = parseInt(process.env.STRATEGY_SERVICE_PORT || '3004');
|
||||
|
||||
// Health check endpoint
|
||||
|
|
|
|||
4
libs/cache/src/decorators/cacheable.ts
vendored
4
libs/cache/src/decorators/cacheable.ts
vendored
|
|
@ -1,8 +1,8 @@
|
|||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { CacheProvider } from '../types';
|
||||
import { CacheKeyGenerator } from '../key-generator';
|
||||
|
||||
const logger = createLogger('cache-decorator');
|
||||
const logger = getLogger('cache-decorator');
|
||||
|
||||
/**
|
||||
* Method decorator for automatic caching
|
||||
|
|
|
|||
4
libs/cache/src/providers/hybrid-cache.ts
vendored
4
libs/cache/src/providers/hybrid-cache.ts
vendored
|
|
@ -1,4 +1,4 @@
|
|||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { CacheProvider, CacheOptions, CacheStats } from '../types';
|
||||
import { RedisCache } from './redis-cache';
|
||||
import { MemoryCache } from './memory-cache';
|
||||
|
|
@ -10,7 +10,7 @@ import { MemoryCache } from './memory-cache';
|
|||
export class HybridCache implements CacheProvider {
|
||||
private memoryCache: MemoryCache;
|
||||
private redisCache: RedisCache;
|
||||
private logger = createLogger('hybrid-cache');
|
||||
private logger = getLogger('hybrid-cache');
|
||||
private enableMetrics: boolean;
|
||||
private startTime = Date.now();
|
||||
|
||||
|
|
|
|||
4
libs/cache/src/providers/memory-cache.ts
vendored
4
libs/cache/src/providers/memory-cache.ts
vendored
|
|
@ -1,4 +1,4 @@
|
|||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { CacheProvider, CacheOptions, CacheStats } from '../types';
|
||||
|
||||
interface CacheEntry<T> {
|
||||
|
|
@ -12,7 +12,7 @@ interface CacheEntry<T> {
|
|||
*/
|
||||
export class MemoryCache implements CacheProvider {
|
||||
private store = new Map<string, CacheEntry<any>>();
|
||||
private logger = createLogger('memory-cache');
|
||||
private logger = getLogger('memory-cache');
|
||||
private defaultTTL: number;
|
||||
private keyPrefix: string;
|
||||
private maxItems: number;
|
||||
|
|
|
|||
4
libs/cache/src/providers/redis-cache.ts
vendored
4
libs/cache/src/providers/redis-cache.ts
vendored
|
|
@ -1,5 +1,5 @@
|
|||
import Redis from 'ioredis';
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { dragonflyConfig } from '@stock-bot/config';
|
||||
import { CacheProvider, CacheOptions, CacheStats } from '../types';
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ import { CacheProvider, CacheOptions, CacheStats } from '../types';
|
|||
*/
|
||||
export class RedisCache implements CacheProvider {
|
||||
private redis: Redis;
|
||||
private logger = createLogger('redis-cache');
|
||||
private logger = getLogger('redis-cache');
|
||||
private defaultTTL: number;
|
||||
private keyPrefix: string;
|
||||
private enableMetrics: boolean;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
export interface DataFrameRow {
|
||||
[key: string]: any;
|
||||
|
|
@ -23,7 +23,7 @@ export class DataFrame {
|
|||
private _columns: string[];
|
||||
private _index: string;
|
||||
private _dtypes: Record<string, 'number' | 'string' | 'boolean' | 'date'>;
|
||||
private logger = createLogger('dataframe');
|
||||
private logger = getLogger('dataframe');
|
||||
|
||||
constructor(data: DataFrameRow[] = [], options: DataFrameOptions = {}) {
|
||||
this.data = [...data];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { EventEmitter } from 'eventemitter3';
|
||||
import Redis from 'ioredis';
|
||||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { dragonflyConfig } from '@stock-bot/config';
|
||||
|
||||
export interface EventBusMessage {
|
||||
|
|
@ -51,7 +51,7 @@ export class EventBus extends EventEmitter {
|
|||
this.useStreams = options.useStreams ?? true;
|
||||
this.maxRetries = options.maxRetries ?? 3;
|
||||
this.retryDelay = options.retryDelay ?? 1000;
|
||||
this.logger = createLogger(`event-bus:${this.serviceName}`);
|
||||
this.logger = getLogger(`event-bus:${this.serviceName}`);
|
||||
|
||||
this.redis = new Redis({
|
||||
host: dragonflyConfig.DRAGONFLY_HOST,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export class HttpClient {
|
|||
|
||||
constructor(config: HttpClientConfig = {}, logger?: Logger) {
|
||||
this.config = config;
|
||||
this.logger = logger?.child({ component: 'http' });
|
||||
this.logger = logger?.child('http-client');
|
||||
}
|
||||
|
||||
// Convenience methods
|
||||
|
|
@ -64,11 +64,19 @@ export class HttpClient {
|
|||
|
||||
return response;
|
||||
} catch (error) {
|
||||
this.logger?.warn('HTTP request failed', {
|
||||
method: finalConfig.method,
|
||||
url: finalConfig.url,
|
||||
error: (error as Error).message,
|
||||
});
|
||||
if( this.logger?.getServiceName() === 'proxy-service' ) {
|
||||
this.logger?.debug('HTTP request failed', {
|
||||
method: finalConfig.method,
|
||||
url: finalConfig.url,
|
||||
error: (error as Error).message,
|
||||
});
|
||||
}else{
|
||||
this.logger?.warn('HTTP request failed', {
|
||||
method: finalConfig.method,
|
||||
url: finalConfig.url,
|
||||
error: (error as Error).message,
|
||||
});
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -117,8 +125,7 @@ export class HttpClient {
|
|||
return response;
|
||||
} catch (error) {
|
||||
const elapsed = Date.now() - startTime;
|
||||
console.log(`Request Aborted after ${elapsed}ms due to timeout of ${timeout}ms`);
|
||||
|
||||
this.logger?.debug('Adapter failed successful', { url: config.url, elapsedMs: Date.now() - startTime });
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
// Handle timeout
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
// Core logger classes and functions
|
||||
export {
|
||||
Logger,
|
||||
createLogger,
|
||||
getLogger,
|
||||
shutdownLoggers
|
||||
} from './logger';
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ function createTransports(serviceName: string): any {
|
|||
options: {
|
||||
colorize: true,
|
||||
translateTime: 'yyyy-mm-dd HH:MM:ss.l',
|
||||
messageFormat: '[{service}] {msg}',
|
||||
messageFormat: '[{service}{childName}] {msg}',
|
||||
singleLine: true,
|
||||
hideObject: false,
|
||||
ignore: 'pid,hostname,service,environment,version',
|
||||
ignore: 'pid,hostname,service,environment,version,childName',
|
||||
errorLikeObjectKeys: ['err', 'error'],
|
||||
errorProps: 'message,stack,name,code',
|
||||
}
|
||||
|
|
@ -61,7 +61,8 @@ function createTransports(serviceName: string): any {
|
|||
labels: {
|
||||
service: serviceName,
|
||||
environment: lokiConfig.LOKI_ENVIRONMENT_LABEL
|
||||
}
|
||||
},
|
||||
ignore: 'childName',
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -102,10 +103,13 @@ function getPinoLogger(serviceName: string): pino.Logger {
|
|||
export class Logger {
|
||||
private pino: pino.Logger;
|
||||
private context: LogContext;
|
||||
private serviceName: string;
|
||||
private childName?: string;
|
||||
|
||||
constructor(serviceName: string, context: LogContext = {}) {
|
||||
this.pino = getPinoLogger(serviceName);
|
||||
this.context = context;
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -198,12 +202,31 @@ export class Logger {
|
|||
/**
|
||||
* Create child logger with additional context
|
||||
*/
|
||||
child(context: LogContext): Logger {
|
||||
child(serviceName: string, context?: LogContext): Logger {
|
||||
// Create child logger that shares the same pino instance with additional context
|
||||
const childLogger = Object.create(Logger.prototype);
|
||||
childLogger.serviceName = this.serviceName;
|
||||
childLogger.childName = serviceName;
|
||||
childLogger.context = { ...this.context, ...context };
|
||||
childLogger.pino = this.pino.child(context); // Let pino handle level inheritance naturally
|
||||
const childBindings = {
|
||||
service: this.serviceName,
|
||||
childName: ' -> ' + serviceName,
|
||||
...(context || childLogger.context)
|
||||
};
|
||||
|
||||
childLogger.pino = this.pino.child(childBindings);
|
||||
return childLogger;
|
||||
// }
|
||||
// childLogger.pino = this.pino.child(context || childLogger.context); // Let pino handle level inheritance naturally
|
||||
// return childLogger;
|
||||
}
|
||||
|
||||
// Getters for service and context
|
||||
getServiceName(): string {
|
||||
return this.serviceName;
|
||||
}
|
||||
getChildName(): string | undefined {
|
||||
return this.childName;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -214,13 +237,6 @@ export function getLogger(serviceName: string, context?: LogContext): Logger {
|
|||
return new Logger(serviceName, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep backward compatibility
|
||||
*/
|
||||
export function createLogger(serviceName: string): pino.Logger {
|
||||
return getPinoLogger(serviceName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gracefully shutdown all logger instances
|
||||
* This should be called during application shutdown to ensure all logs are flushed
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
|
||||
import { Logger, getLogger, createLogger, shutdownLoggers } from '../src';
|
||||
import { Logger, getLogger, shutdownLoggers } from '../src';
|
||||
import { loggerTestHelpers } from './setup';
|
||||
|
||||
describe('Basic Logger Tests', () => {
|
||||
|
|
@ -32,13 +32,6 @@ describe('Basic Logger Tests', () => {
|
|||
anotherTestLoggerInstance.logger.info('Factory test');
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('should create Pino logger with createLogger', () => {
|
||||
expect(typeof createLogger).toBe('function');
|
||||
|
||||
// Test that createLogger function exists
|
||||
expect(() => createLogger).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Logger Methods', () => {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
|
||||
import {
|
||||
Logger,
|
||||
createLogger,
|
||||
getLogger,
|
||||
shutdownLoggers
|
||||
} from '../src';
|
||||
|
|
@ -101,7 +100,6 @@ describe('Logger Integration Tests', () => {
|
|||
describe('Factory Functions', () => {
|
||||
it('should export factory functions', () => {
|
||||
// Verify that the factory functions are exported and callable
|
||||
expect(typeof createLogger).toBe('function');
|
||||
expect(typeof getLogger).toBe('function');
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -19,63 +19,7 @@ const originalConsole = {
|
|||
|
||||
// Create a test logger helper
|
||||
export const loggerTestHelpers = {
|
||||
/**
|
||||
* Create a test logger instance that captures logs locally.
|
||||
*/
|
||||
createTestLogger: (serviceName: string = 'test-service', initialContext: any = {}) => {
|
||||
const capturedLogsArray: any[] = [];
|
||||
|
||||
const createLoggerMockInstance = (currentContext: any): Logger => {
|
||||
const buildLogEntry = (level: string, messageOrObject: string | object, metadata?: any) => {
|
||||
const logObject: any = { level, service: serviceName, ...currentContext };
|
||||
|
||||
if (typeof messageOrObject === 'string') {
|
||||
logObject.msg = messageOrObject;
|
||||
if (metadata) {
|
||||
Object.assign(logObject, metadata);
|
||||
}
|
||||
} else { // messageOrObject is an object
|
||||
Object.assign(logObject, messageOrObject); // Merge fields from the message object
|
||||
if (metadata) { // If metadata is also provided (e.g. logger.error({code: 1}, {extra: 'data'}))
|
||||
Object.assign(logObject, metadata);
|
||||
}
|
||||
// Ensure 'msg' field exists, defaulting if necessary
|
||||
if (typeof logObject.msg === 'undefined') {
|
||||
// If the second arg was a string, it might have been intended as the message
|
||||
if (typeof metadata === 'string') {
|
||||
logObject.msg = metadata;
|
||||
} else {
|
||||
logObject.msg = 'Object logged';
|
||||
}
|
||||
}
|
||||
}
|
||||
capturedLogsArray.push(logObject);
|
||||
};
|
||||
|
||||
return {
|
||||
// serviceName, // For inspection if needed, though logs capture it
|
||||
context: currentContext, // For inspection
|
||||
debug: (msgOrObj: string | object, meta?: any) => buildLogEntry('debug', msgOrObj, meta),
|
||||
info: (msgOrObj: string | object, meta?: any) => buildLogEntry('info', msgOrObj, meta),
|
||||
warn: (msgOrObj: string | object, meta?: any) => buildLogEntry('warn', msgOrObj, meta),
|
||||
error: (msgOrObj: string | object, metaOrMsg?: any) => buildLogEntry('error', msgOrObj, metaOrMsg),
|
||||
child: (childContext: any): Logger => {
|
||||
// Children will log to the same capturedLogsArray
|
||||
return createLoggerMockInstance({ ...currentContext, ...childContext });
|
||||
}
|
||||
} as any; // Cast to Logger, assuming it fulfills the interface for testing purposes
|
||||
};
|
||||
|
||||
const loggerInstance = createLoggerMockInstance(initialContext);
|
||||
|
||||
return {
|
||||
logger: loggerInstance,
|
||||
getCapturedLogs: () => [...capturedLogsArray],
|
||||
clearCapturedLogs: () => {
|
||||
capturedLogsArray.length = 0;
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Mock Loki transport
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Pool } from 'pg';
|
||||
import { questdbConfig } from '@stock-bot/config';
|
||||
import { createLogger, Logger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import type {
|
||||
QuestDBClientConfig,
|
||||
QuestDBConnectionOptions,
|
||||
|
|
@ -24,7 +24,7 @@ export class QuestDBClient {
|
|||
private pgPool: Pool | null = null;
|
||||
private readonly config: QuestDBClientConfig;
|
||||
private readonly options: QuestDBConnectionOptions;
|
||||
private readonly logger = createLogger('QuestDBClient');
|
||||
private readonly logger = getLogger('QuestDBClient');
|
||||
private readonly healthMonitor: QuestDBHealthMonitor;
|
||||
private readonly influxWriter: QuestDBInfluxWriter;
|
||||
private readonly schemaManager: QuestDBSchemaManager;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { EventEmitter } from 'eventemitter3';
|
||||
import { createLogger, Logger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { EventBus } from '@stock-bot/event-bus';
|
||||
import { DataFrame } from '@stock-bot/data-frame';
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ export abstract class BaseStrategy extends EventEmitter {
|
|||
super();
|
||||
this.config = config;
|
||||
this.eventBus = eventBus;
|
||||
this.logger = createLogger(`strategy:${config.id}`);
|
||||
this.logger = getLogger(`strategy:${config.id}`);
|
||||
}
|
||||
|
||||
// Abstract methods that must be implemented by concrete strategies
|
||||
|
|
@ -204,7 +204,7 @@ export class StrategyEngine extends EventEmitter {
|
|||
constructor(eventBus: EventBus) {
|
||||
super();
|
||||
this.eventBus = eventBus;
|
||||
this.logger = createLogger('strategy-engine');
|
||||
this.logger = getLogger('strategy-engine');
|
||||
}
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createLogger } from '@stock-bot/logger';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { DataFrame } from '@stock-bot/data-frame';
|
||||
import { atr, sma, ema, rsi, macd, bollingerBands } from '@stock-bot/utils';
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ export interface VectorizedTrade {
|
|||
|
||||
// Vectorized strategy engine
|
||||
export class VectorEngine {
|
||||
private logger = createLogger('vector-engine');
|
||||
private logger = getLogger('vector-engine');
|
||||
private operations: Map<string, VectorOperation> = new Map();
|
||||
|
||||
constructor() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue