fixed up logger error to make it better to handle in code
This commit is contained in:
parent
db66687f48
commit
d0bb4db042
18 changed files with 51 additions and 45 deletions
|
|
@ -49,7 +49,7 @@ const workInterval = setInterval(() => {
|
|||
try {
|
||||
await initiateShutdown();
|
||||
} catch (error) {
|
||||
logger.error('Manual shutdown failed', { error });
|
||||
logger.error('Manual shutdown failed', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}, 2000);
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ export class UnifiedDataProvider implements DataProvider {
|
|||
try {
|
||||
data = await this.fetchFromQuestDB(symbol, from, to, interval);
|
||||
} catch (error) {
|
||||
logger.warn('Failed to fetch from QuestDB, generating simulated data', { error });
|
||||
logger.warn('Failed to fetch from QuestDB, generating simulated data', error);
|
||||
data = this.generateHistoricalData(symbol, from, to, interval);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ onShutdown(async () => {
|
|||
// await proxyService.shutdown();
|
||||
logger.info('✅ Proxy service cleanup completed');
|
||||
} catch (error) {
|
||||
logger.error('❌ Proxy service cleanup failed', { error });
|
||||
logger.error('❌ Proxy service cleanup failed', error);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -182,7 +182,7 @@ demonstrateCustomProxySource()
|
|||
}, 2000);
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error('💥 Proxy demo failed', { error });
|
||||
logger.error('💥 Proxy demo failed', error);
|
||||
clearShutdownTimer();
|
||||
setTimeout(() => process.exit(1), 1000);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ export class ProxyService {
|
|||
try {
|
||||
await this.scrapeProxies();
|
||||
} catch (error) {
|
||||
this.logger.error('Error in periodic proxy refresh', {error});
|
||||
this.logger.error('Error in periodic proxy refresh', error);
|
||||
}
|
||||
}, intervalMs);
|
||||
}
|
||||
|
|
@ -318,7 +318,7 @@ export class ProxyService {
|
|||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error('Error updating proxy status', {error});
|
||||
this.logger.error('Error updating proxy status', error);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
@ -346,7 +346,7 @@ export class ProxyService {
|
|||
this.logger.warn('No working proxies available');
|
||||
return null;
|
||||
} catch (error) {
|
||||
this.logger.error('Error getting working proxy', {error});
|
||||
this.logger.error('Error getting working proxy', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -371,7 +371,7 @@ export class ProxyService {
|
|||
|
||||
return workingProxies;
|
||||
} catch (error) {
|
||||
this.logger.error('Error getting working proxies', {error});
|
||||
this.logger.error('Error getting working proxies', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
@ -391,7 +391,7 @@ export class ProxyService {
|
|||
this.logger.warn('getAllProxies not fully implemented - Redis cache provider limitations');
|
||||
return proxies;
|
||||
} catch (error) {
|
||||
this.logger.error('Error getting all proxies', {error});
|
||||
this.logger.error('Error getting all proxies', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
@ -424,7 +424,7 @@ export class ProxyService {
|
|||
|
||||
return stats;
|
||||
} catch (error) {
|
||||
this.logger.error('Error getting proxy stats', {error});
|
||||
this.logger.error('Error getting proxy stats', error);
|
||||
return {
|
||||
total: 0,
|
||||
working: 0,
|
||||
|
|
@ -485,7 +485,7 @@ export class ProxyService {
|
|||
stillWorking: successCount
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error('Error in health check', {error});
|
||||
this.logger.error('Error in health check', error);
|
||||
}
|
||||
}, intervalMs);
|
||||
}
|
||||
|
|
@ -502,7 +502,7 @@ export class ProxyService {
|
|||
this.logger.info('Cleared proxy stats from cache');
|
||||
this.logger.warn('Full proxy data clearing not implemented due to cache provider limitations');
|
||||
} catch (error) {
|
||||
this.logger.error('Error clearing proxy data', {error});
|
||||
this.logger.error('Error clearing proxy data', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ async function runBacktest(options: CLIBacktestConfig): Promise<void> {
|
|||
await eventBus.close();
|
||||
|
||||
} catch (error) {
|
||||
logger.error('Backtest failed', { error });
|
||||
logger.error('Backtest failed', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
libs/cache/src/providers/hybrid-cache.ts
vendored
2
libs/cache/src/providers/hybrid-cache.ts
vendored
|
|
@ -185,7 +185,7 @@ export class HybridCache implements CacheProvider {
|
|||
|
||||
return isHealthy;
|
||||
} catch (error) {
|
||||
this.logger.error('Hybrid cache health check failed', { error });
|
||||
this.logger.error('Hybrid cache health check failed', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
libs/cache/src/providers/memory-cache.ts
vendored
2
libs/cache/src/providers/memory-cache.ts
vendored
|
|
@ -222,7 +222,7 @@ export class MemoryCache implements CacheProvider {
|
|||
await this.del('__health_check__');
|
||||
return result === 'ok';
|
||||
} catch (error) {
|
||||
this.logger.error('Memory cache health check failed', { error });
|
||||
this.logger.error('Memory cache health check failed', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
libs/cache/src/providers/redis-cache.ts
vendored
2
libs/cache/src/providers/redis-cache.ts
vendored
|
|
@ -212,7 +212,7 @@ export class RedisCache implements CacheProvider {
|
|||
const pong = await this.redis.ping();
|
||||
return pong === 'PONG' && this.isConnected;
|
||||
} catch (error) {
|
||||
this.logger.error('Redis health check failed', { error });
|
||||
this.logger.error('Redis health check failed', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ export class EventBus extends EventEmitter {
|
|||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to subscribe to event: ${eventType}`, { error });
|
||||
this.logger.error(`Failed to subscribe to event: ${eventType}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -271,7 +271,7 @@ export class EventBus extends EventEmitter {
|
|||
|
||||
} catch (error) {
|
||||
retryCount++;
|
||||
this.logger.error(`Error processing stream message ${msgId} (attempt ${retryCount}):`, { error });
|
||||
this.logger.error(`Error processing stream message ${msgId} (attempt ${retryCount}):`, error);
|
||||
|
||||
if (retryCount >= this.maxRetries) {
|
||||
await this.moveToDeadLetterQueue(msgId, fields, streamKey, groupName, error);
|
||||
|
|
@ -325,7 +325,7 @@ export class EventBus extends EventEmitter {
|
|||
|
||||
this.logger.debug(`Claimed and processed ${claimedMessages.length} pending messages`);
|
||||
} catch (error) {
|
||||
this.logger.error('Error claiming pending messages:', { error });
|
||||
this.logger.error('Error claiming pending messages:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -409,7 +409,7 @@ export class EventBus extends EventEmitter {
|
|||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to unsubscribe from event: ${eventType}`, { error });
|
||||
this.logger.error(`Failed to unsubscribe from event: ${eventType}`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -446,7 +446,7 @@ export class EventBus extends EventEmitter {
|
|||
try {
|
||||
return await this.redis.xinfo('STREAM', streamKey);
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to get stream info for: ${eventType}`, { error });
|
||||
this.logger.error(`Failed to get stream info for: ${eventType}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -460,7 +460,7 @@ export class EventBus extends EventEmitter {
|
|||
try {
|
||||
return await this.redis.xlen(streamKey);
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to get stream length for: ${eventType}`, { error });
|
||||
this.logger.error(`Failed to get stream length for: ${eventType}`, error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -489,7 +489,7 @@ export class EventBus extends EventEmitter {
|
|||
id
|
||||
}));
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to read stream history for: ${eventType}`, { error });
|
||||
this.logger.error(`Failed to read stream history for: ${eventType}`, error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
@ -503,7 +503,7 @@ export class EventBus extends EventEmitter {
|
|||
try {
|
||||
return await this.redis.xtrim(streamKey, 'MAXLEN', '~', maxLength);
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to trim stream: ${eventType}`, { error });
|
||||
this.logger.error(`Failed to trim stream: ${eventType}`, error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -537,7 +537,7 @@ export class EventBus extends EventEmitter {
|
|||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(`Error replaying event: ${event.id}`, { error });
|
||||
this.logger.error(`Error replaying event: ${event.id}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,8 +135,12 @@ export class Logger {
|
|||
this.log('warn', message, metadata);
|
||||
}
|
||||
|
||||
error(message: string | object, metadata?: LogMetadata & { error?: any }): void {
|
||||
const data = { ...metadata };
|
||||
error(message: string | object, metadata?: LogMetadata & { error?: any } | unknown): void {
|
||||
// If metadata is an Error, normalize it
|
||||
if(metadata instanceof Error){
|
||||
metadata = { error: metadata };
|
||||
}
|
||||
const data = typeof metadata === 'object' ? { ...metadata } : { error: message } as any;
|
||||
|
||||
// Handle any type of error automatically
|
||||
if (data.error) {
|
||||
|
|
|
|||
|
|
@ -145,7 +145,9 @@ describe('Advanced Logger Features', () => {
|
|||
const logs = loggerTestHelpers.getCapturedLogs();
|
||||
expect(logs.length).toBe(1);
|
||||
expect(logs[0].context).toBe('batch processing');
|
||||
}); it('should handle error objects with circular references', () => {
|
||||
});
|
||||
|
||||
it('should handle error objects with circular references', () => {
|
||||
const errorWithCircular: any = { name: 'CircularError', message: 'Circular reference error' };
|
||||
// Create a simple circular reference
|
||||
errorWithCircular.self = errorWithCircular;
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ describe('Basic Logger Tests', () => {
|
|||
const error = new Error('Test error');
|
||||
error.stack = 'Error stack trace';
|
||||
|
||||
logger.error('Error test', { error });
|
||||
logger.error('Error test', error);
|
||||
|
||||
const logs = loggerTestHelpers.getCapturedLogs();
|
||||
expect(logs.length).toBe(1);
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ describe('Logger Integration Tests', () => {
|
|||
const error = new Error('Test error');
|
||||
error.stack = 'Error stack trace';
|
||||
|
||||
logger.error('Error occurred', { error });
|
||||
logger.error('Error occurred', error);
|
||||
|
||||
const logs = loggerTestHelpers.getCapturedLogs();
|
||||
expect(logs.length).toBe(1);
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ export class PostgreSQLClient {
|
|||
} catch (error) {
|
||||
const executionTime = Date.now() - startTime;
|
||||
this.logger.error(`Query failed after ${executionTime}ms:`, {
|
||||
error: (error as Error).message,
|
||||
error,
|
||||
query: text,
|
||||
params
|
||||
});
|
||||
|
|
@ -320,8 +320,8 @@ export class PostgreSQLClient {
|
|||
private setupErrorHandlers(): void {
|
||||
if (!this.pool) return;
|
||||
|
||||
this.pool.on('error', (err) => {
|
||||
this.logger.error('PostgreSQL pool error:', err);
|
||||
this.pool.on('error', (error) => {
|
||||
this.logger.error('PostgreSQL pool error:', error);
|
||||
});
|
||||
|
||||
this.pool.on('connect', () => {
|
||||
|
|
|
|||
|
|
@ -44,13 +44,13 @@ export class QuestDBHealthMonitor {
|
|||
try {
|
||||
await this.performHealthCheck();
|
||||
} catch (error) {
|
||||
this.logger.error('Health check failed', { error });
|
||||
this.logger.error('Health check failed', error);
|
||||
}
|
||||
}, intervalMs);
|
||||
|
||||
// Perform initial health check
|
||||
this.performHealthCheck().catch(error => {
|
||||
this.logger.error('Initial health check failed', { error });
|
||||
this.logger.error('Initial health check failed', error);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -362,7 +362,7 @@ export class QuestDBInfluxWriter {
|
|||
if (attempt <= options.retryAttempts) {
|
||||
await this.sleep(options.retryDelay * attempt); // Exponential backoff
|
||||
} else {
|
||||
throw new Error(`Failed to write to QuestDB after ${options.retryAttempts} attempts: ${error}`);
|
||||
throw new Error(`Failed to write to QuestDB after ${options.retryAttempts} attempts: $error`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -380,7 +380,7 @@ export class QuestDBInfluxWriter {
|
|||
try {
|
||||
await this.flush(options);
|
||||
} catch (error) {
|
||||
this.logger.error('Scheduled flush failed', { error });
|
||||
this.logger.error('Scheduled flush failed', error);
|
||||
}
|
||||
}, options.flushInterval);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ export class QuestDBSchemaManager {
|
|||
await this.createTable(schema);
|
||||
this.logger.info(`Table ${tableName} created successfully`);
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to create table ${tableName}`, { error });
|
||||
this.logger.error(`Failed to create table ${tableName}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ export class QuestDBSchemaManager {
|
|||
await this.client.query(sql);
|
||||
this.logger.info(`Table ${tableName} dropped`);
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to drop table ${tableName}`, { error });
|
||||
this.logger.error(`Failed to drop table ${tableName}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -219,7 +219,7 @@ export class QuestDBSchemaManager {
|
|||
|
||||
return result.rows.length > 0 && result.rows[0].count > 0;
|
||||
} catch (error) {
|
||||
this.logger.error(`Error checking if table exists: ${tableName}`, { error });
|
||||
this.logger.error(`Error checking if table exists: ${tableName}`, error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -260,7 +260,7 @@ export class QuestDBSchemaManager {
|
|||
const stats = await this.getTableStats(tableName);
|
||||
this.logger.info(`Table ${tableName} stats`, stats);
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to optimize table ${tableName}`, { error });
|
||||
this.logger.error(`Failed to optimize table ${tableName}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -280,7 +280,7 @@ export class QuestDBSchemaManager {
|
|||
|
||||
return result.rows[0] || {};
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to get table stats for ${tableName}`, { error });
|
||||
this.logger.error(`Failed to get table stats for ${tableName}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -293,7 +293,7 @@ export class QuestDBSchemaManager {
|
|||
await this.client.query(`TRUNCATE TABLE ${tableName}`);
|
||||
this.logger.info(`Table ${tableName} truncated`);
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to truncate table ${tableName}`, { error });
|
||||
this.logger.error(`Failed to truncate table ${tableName}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ export class VectorEngine {
|
|||
signals
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.error('Vectorized strategy execution failed', { error });
|
||||
this.logger.error('Vectorized strategy execution failed', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -383,7 +383,7 @@ export class VectorEngine {
|
|||
this.logger.info(`Running vectorized backtest for strategy: ${strategy.id}`);
|
||||
results[strategy.id] = await this.executeVectorizedStrategy(data, strategy.code);
|
||||
} catch (error) {
|
||||
this.logger.error(`Backtest failed for strategy: ${strategy.id}`, { error });
|
||||
this.logger.error(`Backtest failed for strategy: ${strategy.id}`, error);
|
||||
// Continue with other strategies
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue