refactor: 替换 console.log 为统一日志工具(任务 3.2/20)
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
import { Resend } from 'resend';
|
import { Resend } from 'resend';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import { logger } from '@/lib/logger';
|
||||||
|
|
||||||
|
const log = logger.child('ContactForm');
|
||||||
|
|
||||||
const companyEmail = process.env.COMPANY_EMAIL || 'contact@novalon.cn';
|
const companyEmail = process.env.COMPANY_EMAIL || 'contact@novalon.cn';
|
||||||
|
|
||||||
@@ -69,14 +72,14 @@ export async function submitContactForm(
|
|||||||
const data = validationResult.data;
|
const data = validationResult.data;
|
||||||
|
|
||||||
if (data.website) {
|
if (data.website) {
|
||||||
console.log('Honeypot field filled, rejecting request');
|
log.warn('Honeypot field filled, rejecting request');
|
||||||
return { success: true, message: '消息已发送' };
|
return { success: true, message: '消息已发送' };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.submitTime) {
|
if (data.submitTime) {
|
||||||
const timeDiff = Date.now() - parseInt(data.submitTime);
|
const timeDiff = Date.now() - parseInt(data.submitTime);
|
||||||
if (timeDiff < 2000) {
|
if (timeDiff < 2000) {
|
||||||
console.log('Submission too fast:', timeDiff);
|
log.warn('Submission too fast:', timeDiff);
|
||||||
return { success: false, error: '提交过快,请稍后再试' };
|
return { success: false, error: '提交过快,请稍后再试' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,7 +87,7 @@ export async function submitContactForm(
|
|||||||
if (data.mathHash && data.mathTimestamp && data.mathAnswer !== undefined) {
|
if (data.mathHash && data.mathTimestamp && data.mathAnswer !== undefined) {
|
||||||
const expectedHash = btoa(`${data.mathAnswer}-${data.mathTimestamp}`);
|
const expectedHash = btoa(`${data.mathAnswer}-${data.mathTimestamp}`);
|
||||||
if (expectedHash !== data.mathHash) {
|
if (expectedHash !== data.mathHash) {
|
||||||
console.log('Invalid math captcha');
|
log.warn('Invalid math captcha');
|
||||||
return { success: false, error: '验证码错误,请重新计算' };
|
return { success: false, error: '验证码错误,请重新计算' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,7 +272,7 @@ export async function submitContactForm(
|
|||||||
return { success: false, error: '邮件发送失败,请稍后重试' };
|
return { success: false, error: '邮件发送失败,请稍后重试' };
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Email sent successfully:', emailData);
|
log.info('Email sent successfully:', emailData);
|
||||||
return { success: true, message: '消息已发送' };
|
return { success: true, message: '消息已发送' };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Contact form submission error:', error);
|
console.error('Contact form submission error:', error);
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
|
import { logger } from '@/lib/logger';
|
||||||
|
|
||||||
|
const log = logger.child('AdminUsers');
|
||||||
import {
|
import {
|
||||||
Users as UsersIcon,
|
Users as UsersIcon,
|
||||||
Plus,
|
Plus,
|
||||||
@@ -96,7 +99,7 @@ export default function UsersPage() {
|
|||||||
|
|
||||||
const handleDelete = async (userId: string) => {
|
const handleDelete = async (userId: string) => {
|
||||||
if (deletingUserId) {
|
if (deletingUserId) {
|
||||||
console.log('删除操作正在进行中,请勿重复点击');
|
log.warn('删除操作正在进行中,请勿重复点击');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,14 @@
|
|||||||
import Script from 'next/script';
|
import Script from 'next/script';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { GA_MEASUREMENT_ID } from '@/lib/analytics';
|
import { GA_MEASUREMENT_ID } from '@/lib/analytics';
|
||||||
|
import { logger } from '@/lib/logger';
|
||||||
|
|
||||||
|
const log = logger.child('GoogleAnalytics');
|
||||||
|
|
||||||
export function GoogleAnalytics() {
|
export function GoogleAnalytics() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (GA_MEASUREMENT_ID) {
|
if (GA_MEASUREMENT_ID) {
|
||||||
console.log('Google Analytics initialized:', GA_MEASUREMENT_ID);
|
log.info('Google Analytics initialized:', GA_MEASUREMENT_ID);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useReportWebVitals } from 'next/web-vitals';
|
import { useReportWebVitals } from 'next/web-vitals';
|
||||||
|
import { logger } from '@/lib/logger';
|
||||||
|
|
||||||
|
const log = logger.child('WebVitals');
|
||||||
|
|
||||||
export function WebVitals() {
|
export function WebVitals() {
|
||||||
useReportWebVitals((metric) => {
|
useReportWebVitals((metric) => {
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
console.log('[Web Vitals]', metric);
|
log.debug('[Web Vitals]', metric);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
|||||||
Reference in New Issue
Block a user