Download core/logging.py from lljz66/api: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/lljz66/api/resolve/main/core/logging.py
- Command line
-
hf download hf://spaces/lljz66/api/core/logging.py
-
curl -L -o logging.py https://huggingface.co/spaces/lljz66/api/resolve/main/core/logging.py
1.17 kB
| """Logging + request tracking. | |
| Everything goes to stdout so it shows up in the Hugging Face Space runtime | |
| logs. The previous version appended to /app/requests.jsonl, which is ephemeral | |
| on a Space and grows without bound. | |
| """ | |
| from __future__ import annotations | |
| import logging | |
| import os | |
| import sys | |
| _LEVEL = os.environ.get("LOG_LEVEL", "INFO").upper() | |
| def setup_logging() -> logging.Logger: | |
| handler = logging.StreamHandler(sys.stdout) | |
| handler.setFormatter( | |
| logging.Formatter("%(asctime)s %(levelname)s [%(name)s] %(message)s") | |
| ) | |
| root = logging.getLogger() | |
| root.handlers = [handler] | |
| root.setLevel(_LEVEL) | |
| logger = logging.getLogger("vod") | |
| logger.setLevel(_LEVEL) | |
| return logger | |
| log = setup_logging() | |
| def _clean(value: str, limit: int = 240) -> str: | |
| return " ".join(str(value or "").split())[:limit] | |
| def track(action: str, url: str = "", status: str = "", detail: str = "") -> None: | |
| """Emit one structured request event to stdout.""" | |
| log.info( | |
| "event=%s status=%s detail=%s url=%s", | |
| _clean(action, 40), | |
| _clean(status, 60), | |
| _clean(detail), | |
| _clean(url, 300), | |
| ) | |