# -*- coding: utf-8 -*- # @Time : 2023/7/31 14:05 # @Author : XuJiakai # @File : data_clean_statistic # @Software: PyCharm import traceback from data_clean.exception.fetch_exception import FetchException from data_clean.exception.ruler_validation_exception import RulerValidationException from data_clean.statistic.sls_log import get_logger from data_clean.statistic.statistic_filter import filter_data from data_clean.utils import is_windows from loguru import logger as log _log = get_logger() if not is_windows() else log ''' log template: { session_id: 一个session_id代表一条上传数据,可能包含多行记录或多个维度 content: 原始数据 content_type: 0list类型数据,即一个维度整体报错,一般为postfix_func和prefix_func报错 1record类型数据,即某维度的某一行报错,没有错误的数据仍然会上传 tn: 维度名,如果发送成功,则不存在维度名 successful: 1发送成功,0未发送 error: 1存在异常,0不存在异常 error_info: error_type:0 触发校验规则异常,即ruler_validation_exception,1 fetch_exception,9为其它未知异常 ruler_code:error_type为0时才有ruler_code error_msg:报错的msg } ''' def error(data, session_id, ex: Exception, content_type: int, tn: str, original_data): error_type = 1 if isinstance(ex, FetchException) else 9 filter_data(data) filter_data(original_data) _log.error({ "session_id": session_id, "content": data, "original_content": original_data, "content_type": content_type, "tn": tn, "successful": 0, "error": 1, "error_info": { "error_type": error_type, "error_msg": str(ex), "traceback": "".join(traceback.format_exception(ex)) } }) pass def ruler_error(data, session_id, ex: RulerValidationException, content_type: int, tn: str, original_data): filter_data(data) filter_data(original_data) _log.warning({ "session_id": session_id, "content": data, "original_content": original_data, "content_type": content_type, "tn": tn, "successful": 0, "error": 1, "error_info": { "error_type": 0, "ruler_code": ex.get_ruler_code(), "error_msg": ex.get_msg() } }) pass def success(data, session_id, original_data): filter_data(data) filter_data(original_data) _log.info({ "session_id": session_id, "content": data, "original_content": original_data, "successful": 1, "error": 0, }) pass