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.
 
 
 
 

37 line
1.2 KiB

  1. import urllib3
  2. import pytz
  3. import logging
  4. import warnings
  5. import os
  6. from datetime import datetime
  7. from typing import Any, Dict
  8. # --- SILENZIAMENTO IMMEDIATO ---
  9. # Questo agisce prima ancora che 'requests' possa generare warning
  10. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  11. warnings.filterwarnings("ignore", category=urllib3.exceptions.InsecureRequestWarning)
  12. logging.getLogger("urllib3").setLevel(logging.ERROR)
  13. # Silenzia anche i warning di sklearn/numpy se necessario
  14. os.environ["PYTHONWARNINGS"] = "ignore:Unverified HTTPS request"
  15. # Variabile globale per la Timezone
  16. _current_tz = pytz.UTC
  17. def setup_global_logging(settings: Dict[str, Any]):
  18. """Configura la Timezone in base al config.yaml."""
  19. global _current_tz
  20. debug_cfg = settings.get("debug", {})
  21. tz_name = debug_cfg.get("timezone", "Europe/Rome")
  22. try:
  23. _current_tz = pytz.timezone(tz_name)
  24. except Exception:
  25. _current_tz = pytz.UTC
  26. def get_timestamp() -> str:
  27. """Restituisce il timestamp formattato con la TZ corretta."""
  28. return datetime.now(_current_tz).strftime('%Y-%m-%dT%H:%M:%S.000Z')
  29. def log_msg(msg: str):
  30. """Funzione di log standardizzata."""
  31. print(f"{get_timestamp()} {msg}", flush=True)