refactor: replace console.log with structured logger calls

Replace raw `console.log`/`console.error` calls across CLI, API
handlers, and module files with structured logger functions (`step`,
`done`, `warn`, `fail`) from the shared logger library.

This improves log consistency, readability, and makes it easier to
control output formatting and log levels from a single place.
This commit is contained in:
2026-04-12 21:44:00 -04:00
parent dd7c54d913
commit e87bd05fa4
25 changed files with 218 additions and 189 deletions
+2 -1
View File
@@ -8,6 +8,7 @@
import { register, login, requestPasswordReset, resetPassword, verifyUserEmail } from '../lib/auth.js';
import { validateSession, deleteSession } from '../lib/session.js';
import { verifyEmailToken, verifyResetToken, sendVerificationEmail, sendPasswordResetEmail } from '../lib/email.js';
import { fail } from '../../../shared/lib/logger.js';
import { cookies, headers } from 'next/headers';
import { getSessionCookieName, getPublicBaseUrl } from '../../../shared/lib/appConfig.js';
import { checkRateLimit, getIpFromHeaders, formatRetryAfter } from '../lib/rateLimit.js';
@@ -228,7 +229,7 @@ export async function getSession() {
return result;
} catch (error) {
console.error('Session validation error:', error);
fail(`Auth: session validation error: ${error.message}`);
return null;
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
import { create, findOne, updateById, count } from '../../../core/database/crud.js';
import { hashPassword, verifyPassword, generateId } from './password.js';
import { createSession } from './session.js';
import { fail } from '../../../shared/lib/logger.js';
import { createEmailVerification, createPasswordReset, verifyResetToken, deleteResetToken, sendPasswordChangedEmail } from './email.js';
/**
@@ -251,7 +252,7 @@ async function resetPassword(resetData) {
await sendPasswordChangedEmail(email);
} catch (error) {
// Log error but don't fail the password reset process
console.error(`[ZEN AUTH] Failed to send password changed email to ${email}:`, error.message);
fail(`Auth: failed to send password changed email to ${email}: ${error.message}`);
}
return { success: true };
+7 -6
View File
@@ -6,6 +6,7 @@
import crypto from 'crypto';
import { create, findOne, deleteWhere } from '../../../core/database/crud.js';
import { generateToken, generateId } from './password.js';
import { fail, info } from '../../../shared/lib/logger.js';
import { sendAuthEmail } from '../../../core/email/index.js';
import { renderVerificationEmail, renderPasswordResetEmail, renderPasswordChangedEmail } from '../../../core/email/templates/index.js';
@@ -178,11 +179,11 @@ async function sendVerificationEmail(email, token, baseUrl) {
});
if (!result.success) {
console.error(`[ZEN AUTH] Failed to send verification email to ${email}:`, result.error);
fail(`Auth: failed to send verification email to ${email}: ${result.error}`);
throw new Error('Failed to send verification email');
}
console.log(`[ZEN AUTH] Verification email sent to ${email}`);
info(`Auth: verification email sent to ${email}`);
return result;
}
@@ -205,11 +206,11 @@ async function sendPasswordResetEmail(email, token, baseUrl) {
});
if (!result.success) {
console.error(`[ZEN AUTH] Failed to send password reset email to ${email}:`, result.error);
fail(`Auth: failed to send password reset email to ${email}: ${result.error}`);
throw new Error('Failed to send password reset email');
}
console.log(`[ZEN AUTH] Password reset email sent to ${email}`);
info(`Auth: password reset email sent to ${email}`);
return result;
}
@@ -229,11 +230,11 @@ async function sendPasswordChangedEmail(email) {
});
if (!result.success) {
console.error(`[ZEN AUTH] Failed to send password changed email to ${email}:`, result.error);
fail(`Auth: failed to send password changed email to ${email}: ${result.error}`);
throw new Error('Failed to send password changed email');
}
console.log(`[ZEN AUTH] Password changed email sent to ${email}`);
info(`Auth: password changed email sent to ${email}`);
return result;
}