def handle(self, *args, **options): redis_client = get_log_redis_client() private_queue_name = get_private_queue_name() while True: try: main(redis_client, private_queue_name) except Exception: logger.exception('hit log persistence have error') time.sleep(0.1)
def handle(self, *args, **options): redis_client = get_log_redis_client() private_queue_name = get_private_queue_name() while True: sp_log = redis_client.lindex(private_queue_name, -1) if not sp_log: sp_log = redis_client.rpoplpush(HIT_LOG_QUEUE_NAME, private_queue_name) if sp_log: process_hit_log_msg(sp_log) redis_client.rpop(private_queue_name) else: time.sleep(0.1)
import os import logging import logging.config import logging.handlers from config import LOG_HOME from .handler import RedisHandler from config import HIT_LOG_QUEUE_NAME from clients import get_log_redis_client __all__ = ['init_log', 'hit_logger'] conn = get_log_redis_client() if not os.path.exists(LOG_HOME): os.mkdir(LOG_HOME) # 文本日志 logger_file = os.path.join(LOG_HOME, 'risk_control.log') logging_config = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'hit': { 'format': '%(asctime)s|%(message)s', }, 'detail': {