feat: structured DEBUG/INFO logging via loguru
- common/logging.py: improve format to timestamp|LEVEL|module:func:line - message - core/ layer: DEBUG log every subprocess invocation (cmd, rc, byte counts), JSON load/dump events, parsed application_id. ERROR log on failures. - tools/ layer: DEBUG log every public tool entry with key parameters, INFO log on business outcomes (saved/submitted/killed/...). - New tests/unit/test_logging.py: capture loguru output via in-memory sink and assert DEBUG + INFO messages are emitted for representative flows.
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
"""
|
||||
import subprocess
|
||||
|
||||
from common.logging import logger
|
||||
|
||||
|
||||
class SparkSubmitError(Exception):
|
||||
"""Raised when spark-submit exits with a non-zero return code."""
|
||||
@@ -33,12 +35,19 @@ def build_spark_submit_command(
|
||||
for key, value in (spark_conf or {}).items():
|
||||
cmd.extend(["--conf", f"{key}={value}"])
|
||||
cmd.append(script_path)
|
||||
logger.debug(f"build_spark_submit_command -> {cmd}")
|
||||
return cmd
|
||||
|
||||
|
||||
def run_spark_submit(cmd: list[str]) -> "subprocess.CompletedProcess[str]":
|
||||
logger.debug(f"run_spark_submit exec: {cmd}")
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, errors="replace")
|
||||
logger.debug(
|
||||
f"run_spark_submit done rc={result.returncode} "
|
||||
f"stdout_len={len(result.stdout)} stderr_len={len(result.stderr)}"
|
||||
)
|
||||
if result.returncode != 0:
|
||||
logger.error(f"spark-submit failed (rc={result.returncode}): {result.stderr[:500]}")
|
||||
raise SparkSubmitError(
|
||||
f"spark-submit failed (rc={result.returncode}): {result.stderr}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user