Files
automaker/apps/server/src/lib/events.ts
Shirone 96a999817f feat: implement structured logging across server components
- Integrated a centralized logging system using createLogger from @automaker/utils, replacing console.log and console.error statements with logger methods for consistent log formatting and improved readability.
- Updated various modules, including auth, events, and services, to utilize the new logging system, enhancing error tracking and operational visibility.
- Refactored logging messages to provide clearer context and information, ensuring better maintainability and debugging capabilities.

This update significantly enhances the observability of the server components, facilitating easier troubleshooting and monitoring.
2026-01-02 15:40:15 +01:00

40 lines
975 B
TypeScript

/**
* Event emitter for streaming events to WebSocket clients
*/
import type { EventType, EventCallback } from '@automaker/types';
import { createLogger } from '@automaker/utils';
const logger = createLogger('Events');
// Re-export event types from shared package
export type { EventType, EventCallback };
export interface EventEmitter {
emit: (type: EventType, payload: unknown) => void;
subscribe: (callback: EventCallback) => () => void;
}
export function createEventEmitter(): EventEmitter {
const subscribers = new Set<EventCallback>();
return {
emit(type: EventType, payload: unknown) {
for (const callback of subscribers) {
try {
callback(type, payload);
} catch (error) {
logger.error('Error in event subscriber:', error);
}
}
},
subscribe(callback: EventCallback) {
subscribers.add(callback);
return () => {
subscribers.delete(callback);
};
},
};
}