chore(logging): 降噪 PDD 同步与发单消费者常态日志
将无新单/全跳过的处理完成日志降到 debug,并压缩 decisions 详情,避免 app 日志被按日切碎。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -25,7 +25,7 @@ import {
|
||||
import { findExistingPlatformOrderIds } from '../../../repositories/order-repo.js'
|
||||
import { notifyPddCookieExpired } from '../../notification/domain-notifications.js'
|
||||
import { upsertOrderFromSource } from '../../order/order-service.js'
|
||||
import { logError, logInfo, logWarn } from '../../../utils/logger.js'
|
||||
import { logDebug, logError, logInfo, logWarn } from '../../../utils/logger.js'
|
||||
|
||||
export interface SyncStoreOrdersOptions {
|
||||
pageNumber?: number | undefined
|
||||
@@ -44,6 +44,8 @@ export interface SyncStoreResult {
|
||||
total: number
|
||||
fetchedCount: number
|
||||
upsertedCount: number
|
||||
/** 本轮判定为库内未见过的新单数量(用于日志降噪,不等于 upsert 次数)。 */
|
||||
newOrderCount: number
|
||||
ignoredCount: number
|
||||
failedCount: number
|
||||
pagesFetched: number
|
||||
@@ -108,6 +110,7 @@ export async function syncStoreOrders(
|
||||
total: 0,
|
||||
fetchedCount: 0,
|
||||
upsertedCount: 0,
|
||||
newOrderCount: 0,
|
||||
ignoredCount: 0,
|
||||
failedCount: 0,
|
||||
pagesFetched: 0,
|
||||
@@ -136,6 +139,7 @@ export async function syncStoreOrders(
|
||||
let totalReported = 0
|
||||
let totalFetched = 0
|
||||
let totalUpserted = 0
|
||||
let totalNewOrders = 0
|
||||
let totalIgnored = 0
|
||||
let totalFailed = 0
|
||||
|
||||
@@ -179,6 +183,7 @@ export async function syncStoreOrders(
|
||||
|
||||
const existingCountOnPage = existingOrderSns.size
|
||||
const newCountOnPage = pageOrderSns.length - existingCountOnPage
|
||||
totalNewOrders += Math.max(0, newCountOnPage)
|
||||
|
||||
const doUpsert = options.upsertFn || upsertOrderFromSource
|
||||
|
||||
@@ -205,7 +210,9 @@ export async function syncStoreOrders(
|
||||
}
|
||||
}
|
||||
|
||||
logInfo(
|
||||
// 本页无新单时降到 debug,避免每 20s 一轮把日志打满。
|
||||
const pageLog = newCountOnPage > 0 || totalFailed > 0 ? logInfo : logDebug
|
||||
pageLog(
|
||||
'[pdd-sync]',
|
||||
`店铺 ${shopName} 第 ${currentPage} 页处理完成 (本页拉取: ${items.length}, 新单: ${newCountOnPage}, 库中已有: ${existingCountOnPage})`,
|
||||
{
|
||||
@@ -269,12 +276,15 @@ export async function syncStoreOrders(
|
||||
totalOrders: totalReported,
|
||||
}).catch(() => null)
|
||||
|
||||
logInfo('[pdd-sync]', `店铺 ${shopName} 同步完成 (共拉取 ${pagesFetched} 页)`, {
|
||||
// 仅「真正新单 / 失败 / 多页回填」打 info;常态触达旧单后停页的空跑降到 debug。
|
||||
const storeDoneLog = totalNewOrders > 0 || totalFailed > 0 || pagesFetched > 1 ? logInfo : logDebug
|
||||
storeDoneLog('[pdd-sync]', `店铺 ${shopName} 同步完成 (共拉取 ${pagesFetched} 页)`, {
|
||||
shopId,
|
||||
total: totalReported,
|
||||
pagesFetched,
|
||||
fetchedCount: totalFetched,
|
||||
upsertedCount: totalUpserted,
|
||||
newOrderCount: totalNewOrders,
|
||||
ignoredCount: totalIgnored,
|
||||
failedCount: totalFailed,
|
||||
})
|
||||
@@ -285,6 +295,7 @@ export async function syncStoreOrders(
|
||||
total: totalReported,
|
||||
fetchedCount: totalFetched,
|
||||
upsertedCount: totalUpserted,
|
||||
newOrderCount: totalNewOrders,
|
||||
ignoredCount: totalIgnored,
|
||||
failedCount: totalFailed,
|
||||
pagesFetched,
|
||||
@@ -319,6 +330,7 @@ export async function syncStoreOrders(
|
||||
total: totalReported,
|
||||
fetchedCount: totalFetched,
|
||||
upsertedCount: totalUpserted,
|
||||
newOrderCount: totalNewOrders,
|
||||
ignoredCount: totalIgnored,
|
||||
failedCount: totalFailed,
|
||||
pagesFetched,
|
||||
|
||||
Reference in New Issue
Block a user