Refactor logging in hooks, services, and routes to use centralized logger
- Replaced console.log and console.error statements with logger.info and logger.error in new-hook.ts, SDKAgent.ts, SessionManager.ts, and SessionRoutes.ts for consistent logging. - Introduced log file creation and management in logger.ts, ensuring logs are saved to a file with a date-based naming convention. - Enhanced error handling in logger to prevent crashes if log file operations fail.
This commit is contained in:
@@ -64,7 +64,7 @@ export class SDKAgent {
|
||||
// Create message generator (event-driven)
|
||||
const messageGenerator = this.createMessageGenerator(session);
|
||||
|
||||
console.log('[SDK-AGENT] Starting SDK query with:', {
|
||||
logger.info('SDK', 'Starting SDK query', {
|
||||
sessionDbId: session.sessionDbId,
|
||||
claudeSessionId: session.claudeSessionId,
|
||||
resume_parameter: session.claudeSessionId,
|
||||
@@ -205,7 +205,7 @@ export class SDKAgent {
|
||||
|
||||
// Build initial prompt
|
||||
const isInitPrompt = session.lastPromptNumber === 1;
|
||||
console.log('[SDK-AGENT] Creating message generator:', {
|
||||
logger.info('SDK', 'Creating message generator', {
|
||||
sessionDbId: session.sessionDbId,
|
||||
claudeSessionId: session.claudeSessionId,
|
||||
lastPromptNumber: session.lastPromptNumber,
|
||||
|
||||
@@ -47,7 +47,7 @@ export class SessionManager {
|
||||
* Initialize a new session or return existing one
|
||||
*/
|
||||
initializeSession(sessionDbId: number, currentUserPrompt?: string, promptNumber?: number): ActiveSession {
|
||||
console.log('[SESSION-MANAGER] initializeSession called:', {
|
||||
logger.info('SESSION', 'initializeSession called', {
|
||||
sessionDbId,
|
||||
promptNumber,
|
||||
has_currentUserPrompt: !!currentUserPrompt
|
||||
@@ -56,7 +56,7 @@ export class SessionManager {
|
||||
// Check if already active
|
||||
let session = this.sessions.get(sessionDbId);
|
||||
if (session) {
|
||||
console.log('[SESSION-MANAGER] Returning cached session:', {
|
||||
logger.info('SESSION', 'Returning cached session', {
|
||||
sessionDbId,
|
||||
claudeSessionId: session.claudeSessionId,
|
||||
lastPromptNumber: session.lastPromptNumber
|
||||
@@ -98,7 +98,7 @@ export class SessionManager {
|
||||
// Fetch from database
|
||||
const dbSession = this.dbManager.getSessionById(sessionDbId);
|
||||
|
||||
console.log('[SESSION-MANAGER] Fetched session from database:', {
|
||||
logger.info('SESSION', 'Fetched session from database', {
|
||||
sessionDbId,
|
||||
claude_session_id: dbSession.claude_session_id,
|
||||
sdk_session_id: dbSession.sdk_session_id
|
||||
@@ -141,7 +141,7 @@ export class SessionManager {
|
||||
currentProvider: null // Will be set when generator starts
|
||||
};
|
||||
|
||||
console.log('[SESSION-MANAGER] Creating new session object:', {
|
||||
logger.info('SESSION', 'Creating new session object', {
|
||||
sessionDbId,
|
||||
claudeSessionId: dbSession.claude_session_id,
|
||||
lastPromptNumber: promptNumber || this.dbManager.getSessionStore().getPromptNumberFromUserPrompts(dbSession.claude_session_id)
|
||||
|
||||
@@ -173,7 +173,7 @@ export class SessionRoutes extends BaseRouteHandler {
|
||||
if (sessionDbId === null) return;
|
||||
|
||||
const { userPrompt, promptNumber } = req.body;
|
||||
console.log('[SESSION-ROUTES] handleSessionInit called:', {
|
||||
logger.info('HTTP', 'SessionRoutes: handleSessionInit called', {
|
||||
sessionDbId,
|
||||
promptNumber,
|
||||
has_userPrompt: !!userPrompt
|
||||
@@ -488,7 +488,7 @@ export class SessionRoutes extends BaseRouteHandler {
|
||||
private handleSessionInitByClaudeId = this.wrapHandler((req: Request, res: Response): void => {
|
||||
const { claudeSessionId, project, prompt } = req.body;
|
||||
|
||||
console.log('[SESSION-ROUTES] handleSessionInitByClaudeId called:', {
|
||||
logger.info('HTTP', 'SessionRoutes: handleSessionInitByClaudeId called', {
|
||||
claudeSessionId,
|
||||
project,
|
||||
prompt_length: prompt?.length
|
||||
@@ -504,7 +504,7 @@ export class SessionRoutes extends BaseRouteHandler {
|
||||
// Step 1: Create/get SDK session (idempotent INSERT OR IGNORE)
|
||||
const sessionDbId = store.createSDKSession(claudeSessionId, project, prompt);
|
||||
|
||||
console.log('[SESSION-ROUTES] createSDKSession returned:', {
|
||||
logger.info('HTTP', 'SessionRoutes: createSDKSession returned', {
|
||||
sessionDbId,
|
||||
claudeSessionId
|
||||
});
|
||||
@@ -513,7 +513,7 @@ export class SessionRoutes extends BaseRouteHandler {
|
||||
const currentCount = store.getPromptNumberFromUserPrompts(claudeSessionId);
|
||||
const promptNumber = currentCount + 1;
|
||||
|
||||
console.log('[SESSION-ROUTES] Calculated promptNumber:', {
|
||||
logger.info('HTTP', 'SessionRoutes: Calculated promptNumber', {
|
||||
sessionDbId,
|
||||
promptNumber,
|
||||
currentCount
|
||||
|
||||
Reference in New Issue
Block a user