feat(logging): add logger
This commit is contained in:
parent
7c84025f3c
commit
aae85cd767
15 changed files with 240 additions and 17 deletions
|
|
@ -4,6 +4,7 @@ import { getChatModel, getChatModelProvider } from '../config';
|
|||
import { getAvailableProviders } from '../lib/providers';
|
||||
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
||||
import type { Embeddings } from '@langchain/core/embeddings';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
export const handleConnection = async (ws: WebSocket) => {
|
||||
const models = await getAvailableProviders();
|
||||
|
|
@ -34,5 +35,5 @@ export const handleConnection = async (ws: WebSocket) => {
|
|||
await handleMessage(message.toString(), ws, llm, embeddings),
|
||||
);
|
||||
|
||||
ws.on('close', () => console.log('Connection closed'));
|
||||
ws.on('close', () => logger.debug('Connection closed'));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import handleYoutubeSearch from '../agents/youtubeSearchAgent';
|
|||
import handleRedditSearch from '../agents/redditSearchAgent';
|
||||
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
||||
import type { Embeddings } from '@langchain/core/embeddings';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
type Message = {
|
||||
type: string;
|
||||
|
|
@ -101,8 +102,8 @@ export const handleMessage = async (
|
|||
ws.send(JSON.stringify({ type: 'error', data: 'Invalid focus mode' }));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to handle message', error);
|
||||
} catch (err) {
|
||||
ws.send(JSON.stringify({ type: 'error', data: 'Invalid message format' }));
|
||||
logger.error(`Failed to handle message: ${err}`);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { WebSocketServer } from 'ws';
|
|||
import { handleConnection } from './connectionManager';
|
||||
import http from 'http';
|
||||
import { getPort } from '../config';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
export const initServer = (
|
||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||
|
|
@ -13,5 +14,5 @@ export const initServer = (
|
|||
handleConnection(ws);
|
||||
});
|
||||
|
||||
console.log(`WebSocket server started on port ${port}`);
|
||||
logger.info(`WebSocket server started on port ${port}`);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue