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:
@@ -38,6 +38,7 @@
|
||||
'use server';
|
||||
|
||||
import { query } from '@zen/core/database';
|
||||
import { fail } from '../../../shared/lib/logger.js';
|
||||
|
||||
/**
|
||||
* Get total number of users
|
||||
@@ -50,7 +51,7 @@ async function getTotalUsersCount() {
|
||||
);
|
||||
return parseInt(result.rows[0].count) || 0;
|
||||
} catch (error) {
|
||||
console.error('Error getting users count:', error);
|
||||
fail(`Error getting users count: ${error.message}`);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -70,7 +71,7 @@ export async function getDashboardStats() {
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error getting dashboard stats:', error);
|
||||
fail(`Error getting dashboard stats: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message || 'Failed to get dashboard statistics'
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user