perf(logging): reduce allow-strategy log noise via env switch
This commit is contained in:
@@ -53,6 +53,7 @@ services:
|
||||
- MAX_IP_ATTEMPTS_PER_HOUR=10
|
||||
# 日志配置
|
||||
- LOG_LEVEL=INFO
|
||||
- SECURITY_LOG_ALLOW_STRATEGY=0
|
||||
- LOG_FILE=logs/app.log
|
||||
- API_DIAGNOSTIC_LOG=0
|
||||
- API_DIAGNOSTIC_SLOW_MS=0
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
@@ -33,6 +34,12 @@ class ResponseHandler:
|
||||
def __init__(self, *, rng: Optional[random.Random] = None) -> None:
|
||||
self._rng = rng or random.SystemRandom()
|
||||
self._logger = get_logger("app")
|
||||
self._log_allow_strategy = str(os.environ.get("SECURITY_LOG_ALLOW_STRATEGY", "0")).strip().lower() in {
|
||||
"1",
|
||||
"true",
|
||||
"yes",
|
||||
"on",
|
||||
}
|
||||
|
||||
def get_strategy(self, risk_score: int, is_banned: bool = False) -> ResponseStrategy:
|
||||
"""
|
||||
@@ -65,7 +72,11 @@ class ResponseHandler:
|
||||
|
||||
strategy.captcha_level = self._normalize_captcha_level(strategy.captcha_level)
|
||||
|
||||
self._logger.info(
|
||||
log_func = self._logger.info
|
||||
if strategy.action == ResponseAction.ALLOW and not self._log_allow_strategy:
|
||||
log_func = self._logger.debug
|
||||
|
||||
log_func(
|
||||
"响应策略: action=%s risk_score=%s delay=%.3f captcha_level=%s",
|
||||
strategy.action.value,
|
||||
score,
|
||||
|
||||
Reference in New Issue
Block a user