Download app/log.py from CJR61/papi_cc: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/CJR61/papi_cc/resolve/main/app/log.py
- Command line
-
hf download hf://spaces/CJR61/papi_cc/app/log.py
-
curl -L -o log.py https://huggingface.co/spaces/CJR61/papi_cc/resolve/main/app/log.py
1.11 kB
| # app/log.py | |
| import logging | |
| import os | |
| logger = logging.getLogger("API Logger") | |
| logger.setLevel(logging.INFO) | |
| def configure_logger(log_dir: str): | |
| """Configure handlers to write logs to the given directory.""" | |
| os.makedirs(log_dir, exist_ok=True) | |
| # 清掉舊 handler,避免重複寫入多次 | |
| logger.handlers.clear() | |
| fmt = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s") | |
| fh = logging.FileHandler(os.path.join(log_dir, "app.log"), encoding="utf-8") | |
| fh.setFormatter(fmt) | |
| sh = logging.StreamHandler() | |
| sh.setFormatter(fmt) | |
| logger.addHandler(fh) | |
| logger.addHandler(sh) | |
| # import logging | |
| # import os | |
| # # Ensure the log directory exists | |
| # log_dir = "logs" | |
| # os.makedirs(log_dir, exist_ok=True) | |
| # # Set up logging configuration | |
| # logging.basicConfig( | |
| # level=logging.INFO, | |
| # format="%(asctime)s [%(levelname)s] %(message)s", | |
| # handlers=[ | |
| # logging.FileHandler(os.path.join(log_dir, "app.log")), # Log output to file | |
| # logging.StreamHandler() # Log output to console | |
| # ] | |
| # ) | |
| # logger = logging.getLogger("API Logger") | |