You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
5.3 KiB
135 lines
5.3 KiB
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// 日志文件路径
|
|
const logFilePath = path.join(__dirname, 'logs', 'output.log');
|
|
|
|
// 读取并分析日志文件
|
|
function analyzeGrossWeightLogs() {
|
|
try {
|
|
console.log(`正在分析日志文件: ${logFilePath}`);
|
|
console.log('搜索与grossWeight相关的日志记录...\n');
|
|
|
|
// 读取日志文件内容
|
|
const logContent = fs.readFileSync(logFilePath, 'utf-8');
|
|
const logLines = logContent.split('\n');
|
|
|
|
// 存储找到的毛重相关记录
|
|
const grossWeightRecords = [];
|
|
const publishRequestRecords = [];
|
|
|
|
// 搜索最近24小时的日志记录
|
|
const twentyFourHoursAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
|
|
|
// 遍历日志行
|
|
for (let i = 0; i < logLines.length; i++) {
|
|
const line = logLines[i];
|
|
|
|
// 检查时间戳是否在最近24小时内
|
|
const timestampMatch = line.match(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})/);
|
|
if (timestampMatch) {
|
|
const logDate = new Date(timestampMatch[1]);
|
|
if (logDate < twentyFourHoursAgo) {
|
|
continue; // 跳过24小时前的日志
|
|
}
|
|
}
|
|
|
|
// 搜索与grossWeight相关的记录
|
|
if (line.includes('grossWeight')) {
|
|
grossWeightRecords.push({
|
|
line: i + 1,
|
|
content: line,
|
|
timestamp: timestampMatch ? timestampMatch[1] : '未知'
|
|
});
|
|
}
|
|
|
|
// 搜索商品发布请求
|
|
if (line.includes('/api/product/publish')) {
|
|
// 收集发布请求的上下文
|
|
const contextLines = [];
|
|
// 向前收集5行
|
|
for (let j = Math.max(0, i - 5); j < Math.min(logLines.length, i + 20); j++) {
|
|
contextLines.push(logLines[j]);
|
|
}
|
|
publishRequestRecords.push({
|
|
line: i + 1,
|
|
content: contextLines.join('\n'),
|
|
timestamp: timestampMatch ? timestampMatch[1] : '未知'
|
|
});
|
|
}
|
|
}
|
|
|
|
// 输出分析结果
|
|
console.log('===== 最近24小时毛重字段处理分析结果 =====\n');
|
|
|
|
console.log(`找到 ${grossWeightRecords.length} 条与grossWeight相关的日志记录\n`);
|
|
|
|
// 显示最近的10条毛重记录
|
|
console.log('最近的10条毛重处理记录:');
|
|
grossWeightRecords.slice(-10).forEach((record, index) => {
|
|
console.log(`[${record.timestamp}] 第${record.line}行: ${record.content}`);
|
|
});
|
|
|
|
console.log('\n');
|
|
|
|
// 显示最近的商品发布请求及其毛重处理
|
|
console.log(`找到 ${publishRequestRecords.length} 条商品发布请求记录`);
|
|
if (publishRequestRecords.length > 0) {
|
|
console.log('\n最近的商品发布请求及毛重处理详情:');
|
|
const latestPublish = publishRequestRecords[publishRequestRecords.length - 1];
|
|
console.log(`\n时间: ${latestPublish.timestamp}`);
|
|
console.log(`起始行号: ${latestPublish.line}`);
|
|
console.log('详细内容:');
|
|
|
|
// 解析请求体中的grossWeight值
|
|
const requestBodyMatch = latestPublish.content.match(/请求体: \{([\s\S]*?)\}/);
|
|
if (requestBodyMatch) {
|
|
console.log(requestBodyMatch[0]);
|
|
|
|
// 提取grossWeight值
|
|
const grossWeightMatch = requestBodyMatch[0].match(/"grossWeight"\s*:\s*(null|\d+(\.\d+)?)/);
|
|
if (grossWeightMatch) {
|
|
console.log(`\n请求中的毛重值: ${grossWeightMatch[1]}`);
|
|
}
|
|
}
|
|
|
|
// 查找毛重处理的相关日志
|
|
const grossWeightProcessingMatch = latestPublish.content.match(/\[发布商品.*\] 原始毛重值:.*|毛重值.*设置为.*|最终处理的毛重值:.*|grossWeightStored:.*|毛重.*转换为数字/);
|
|
if (grossWeightProcessingMatch) {
|
|
console.log('\n毛重处理过程:');
|
|
grossWeightProcessingMatch.forEach(processingLine => {
|
|
console.log(processingLine);
|
|
});
|
|
}
|
|
}
|
|
|
|
// 生成总结
|
|
console.log('\n===== 分析总结 =====');
|
|
if (grossWeightRecords.length === 0) {
|
|
console.log('在最近24小时内没有找到与grossWeight相关的日志记录。');
|
|
} else {
|
|
console.log(`在最近24小时内找到了 ${grossWeightRecords.length} 条与grossWeight相关的日志记录。`);
|
|
|
|
// 简单统计
|
|
const nullGrossWeightCount = grossWeightRecords.filter(r => r.content.includes('grossWeight: null')).length;
|
|
const zeroGrossWeightCount = grossWeightRecords.filter(r => r.content.includes('grossWeight: 0')).length;
|
|
const numericGrossWeightCount = grossWeightRecords.filter(r => /grossWeight:\s*\d+\.\d+/.test(r.content)).length;
|
|
|
|
console.log(`- 毛重为null的记录数: ${nullGrossWeightCount}`);
|
|
console.log(`- 毛重为0的记录数: ${zeroGrossWeightCount}`);
|
|
console.log(`- 毛重为数字的记录数: ${numericGrossWeightCount}`);
|
|
}
|
|
|
|
console.log('\n提示: 如果需要查看更多详细信息,建议直接查看日志文件或使用更专业的日志分析工具。');
|
|
|
|
} catch (error) {
|
|
console.error('分析日志时发生错误:', error.message);
|
|
console.log('\n建议手动查看日志文件:');
|
|
console.log(`1. 打开文件: ${logFilePath}`);
|
|
console.log('2. 搜索关键词: grossWeight');
|
|
console.log('3. 特别关注: 发布商品请求中的grossWeight值和处理过程');
|
|
}
|
|
}
|
|
|
|
// 执行分析
|
|
analyzeGrossWeightLogs();
|