feat: Introduce unified logging system and optimize file management
- Added a new unified logging module to standardize log formatting, including support for traceId and MDC for better tracking. - Updated `.gitignore` to exclude code analysis reports and temporary files. - Created cleanup scripts to manage unused files and generate cleanup reports. - Enhanced existing modules to integrate the new logging system and improve debugging capabilities. - Removed outdated files and scripts to streamline the project structure.
This commit is contained in:
1 parent
08a0b41834
commit
e5a510d19b
45 files changed
+18285
-1357
No files matched your search
@@ -804,6 +804,24 @@ class underlying_operations:
|
||||
douyin_screenshot_manager.save_latest_attempt(
|
||||
cropped_img, operation_type="cut_pic"
|
||||
)
|
||||
|
||||
# 保存调试图像(带详细信息)
|
||||
debug_path = douyin_screenshot_manager.save_debug_image(
|
||||
cropped_img,
|
||||
operation_type="cut_pic",
|
||||
picname=name if name else "cut",
|
||||
step="before_ocr",
|
||||
coords=(left, top, right, bottom),
|
||||
extra_info={
|
||||
"source": "screenshot.png",
|
||||
"size": f"{right-left}x{bottom-top}"
|
||||
}
|
||||
)
|
||||
if debug_path:
|
||||
try:
|
||||
logging.info(f"[调试图像] cut_pic保存: {debug_path}")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -867,12 +885,36 @@ class underlying_operations:
|
||||
continue
|
||||
|
||||
assert cut_pic_path is not None
|
||||
cropped_img = pic.crop((left, top, right, bottom))
|
||||
try:
|
||||
_ensure_parent_dir(cut_pic_path)
|
||||
pic.crop((left, top, right, bottom)).save(cut_pic_path)
|
||||
cropped_img.save(cut_pic_path)
|
||||
except Exception:
|
||||
logging.exception("保存裁剪图片失败: %s", cut_pic_path)
|
||||
return False
|
||||
|
||||
# 保存调试图像
|
||||
try:
|
||||
import douyin_screenshot_manager
|
||||
debug_path = douyin_screenshot_manager.save_debug_image(
|
||||
cropped_img,
|
||||
operation_type="cut_pic",
|
||||
picname=name if name else "cut",
|
||||
step="before_ocr",
|
||||
coords=(left, top, right, bottom),
|
||||
extra_info={
|
||||
"source": target + "/screenshot.png",
|
||||
"size": f"{right-left}x{bottom-top}"
|
||||
}
|
||||
)
|
||||
if debug_path:
|
||||
try:
|
||||
logging.info(f"[调试图像] cut_pic保存: {debug_path}")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return True
|
||||
|
||||
except (SyntaxError, IOError, OSError, FileNotFoundError, ValueError) as e:
|
||||
@@ -952,6 +994,28 @@ class underlying_operations:
|
||||
except Exception:
|
||||
img1 = img # Fallback to original image
|
||||
|
||||
# 保存预处理后的调试图像(OCR前)
|
||||
try:
|
||||
import douyin_screenshot_manager
|
||||
debug_path = douyin_screenshot_manager.save_debug_image(
|
||||
img1,
|
||||
operation_type="ocr",
|
||||
picname=picname,
|
||||
step="preprocessed",
|
||||
extra_info={
|
||||
"mode": change_color,
|
||||
"size": f"{w}x{h}",
|
||||
"source": pic_path if pic_path else picname
|
||||
}
|
||||
)
|
||||
if debug_path:
|
||||
try:
|
||||
logging.info(f"[调试图像] OCR预处理保存: {debug_path}")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
img_np = np.array(img1)
|
||||
|
||||
if getattr(self, "ocr_type", None) == "easyocr":
|
||||
@@ -1020,6 +1084,26 @@ class underlying_operations:
|
||||
douyin_screenshot_manager.save_latest_attempt(
|
||||
img_for_attempt, operation_type="ocr"
|
||||
)
|
||||
|
||||
# 保存OCR结果后的调试图像(带OCR文本结果)
|
||||
ocr_result_preview = (text or text2 or "").strip()[:50] if (text or text2) else ""
|
||||
debug_path = douyin_screenshot_manager.save_debug_image(
|
||||
img_for_attempt,
|
||||
operation_type="ocr",
|
||||
picname=picname,
|
||||
step="after_ocr",
|
||||
extra_info={
|
||||
"mode": change_color,
|
||||
"text_len": len(text or text2 or ""),
|
||||
"text_preview": ocr_result_preview,
|
||||
"used_img2": bool(img2 is not None and text2 and text2.strip())
|
||||
}
|
||||
)
|
||||
if debug_path:
|
||||
try:
|
||||
logging.info(f"[调试图像] OCR结果保存: {debug_path}, 文本: {ocr_result_preview}")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Reference in new issue
Block a user