switched all console logs to logger
This commit is contained in:
parent
3877902ff4
commit
a3f2f199b4
14 changed files with 125 additions and 122 deletions
|
|
@ -9,7 +9,7 @@ export function registerCacheServices(
|
|||
): void {
|
||||
if (config.redis.enabled) {
|
||||
container.register({
|
||||
cache: asFunction(() => {
|
||||
cache: asFunction(({ logger }) => {
|
||||
const { createServiceCache } = require('@stock-bot/queue');
|
||||
// Get standardized service name from config
|
||||
const serviceName = config.service?.serviceName || config.service?.name || 'unknown';
|
||||
|
|
@ -20,11 +20,11 @@ export function registerCacheServices(
|
|||
port: config.redis.port,
|
||||
password: config.redis.password,
|
||||
db: config.redis.db, // This will be overridden by ServiceCache
|
||||
});
|
||||
}, { logger });
|
||||
}).singleton(),
|
||||
|
||||
// Also provide global cache for shared data
|
||||
globalCache: asFunction(() => {
|
||||
globalCache: asFunction(({ logger }) => {
|
||||
const { createServiceCache } = require('@stock-bot/queue');
|
||||
const serviceName = config.service?.serviceName || config.service?.name || 'unknown';
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ export function registerCacheServices(
|
|||
host: config.redis.host,
|
||||
port: config.redis.port,
|
||||
password: config.redis.password,
|
||||
}, { global: true });
|
||||
}, { global: true, logger });
|
||||
}).singleton(),
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ export class ServiceApplication {
|
|||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('DETAILED ERROR:', error);
|
||||
this.logger.error('DETAILED ERROR:', error);
|
||||
this.logger.error('Failed to start service', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import type { AwilixContainer } from 'awilix';
|
||||
import type { ServiceDefinitions } from '../container/types';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
interface ServiceWithLifecycle {
|
||||
connect?: () => Promise<void>;
|
||||
|
|
@ -10,6 +11,7 @@ interface ServiceWithLifecycle {
|
|||
}
|
||||
|
||||
export class ServiceLifecycleManager {
|
||||
private readonly logger = getLogger('service-lifecycle');
|
||||
private readonly services = [
|
||||
{ name: 'cache', key: 'cache' as const },
|
||||
{ name: 'mongoClient', key: 'mongoClient' as const },
|
||||
|
|
@ -40,7 +42,7 @@ export class ServiceLifecycleManager {
|
|||
}
|
||||
|
||||
await Promise.all(initPromises);
|
||||
console.log('✅ All services initialized successfully');
|
||||
this.logger.info('All services initialized successfully');
|
||||
}
|
||||
|
||||
async shutdownServices(container: AwilixContainer<ServiceDefinitions>): Promise<void> {
|
||||
|
|
@ -56,20 +58,20 @@ export class ServiceLifecycleManager {
|
|||
}
|
||||
|
||||
await Promise.allSettled(shutdownPromises);
|
||||
console.log('✅ All services shut down');
|
||||
this.logger.info('All services shut down');
|
||||
}
|
||||
|
||||
private async initializeService(name: string, service: ServiceWithLifecycle): Promise<void> {
|
||||
try {
|
||||
if (typeof service.connect === 'function') {
|
||||
await service.connect();
|
||||
console.log(`✅ ${name} connected`);
|
||||
this.logger.info(`${name} connected`);
|
||||
} else if (typeof service.initialize === 'function') {
|
||||
await service.initialize();
|
||||
console.log(`✅ ${name} initialized`);
|
||||
this.logger.info(`${name} initialized`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`❌ Failed to initialize ${name}:`, error);
|
||||
this.logger.error(`Failed to initialize ${name}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -83,9 +85,9 @@ export class ServiceLifecycleManager {
|
|||
} else if (typeof service.shutdown === 'function') {
|
||||
await service.shutdown();
|
||||
}
|
||||
console.log(`✅ ${name} shut down`);
|
||||
this.logger.info(`${name} shut down`);
|
||||
} catch (error) {
|
||||
console.error(`❌ Error shutting down ${name}:`, error);
|
||||
this.logger.error(`Error shutting down ${name}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,4 +96,4 @@ export class ServiceLifecycleManager {
|
|||
setTimeout(() => reject(new Error(message)), timeout);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue