Spaces:
Runtime error
Runtime error
Download utils/logging.py from PageOrg/summaryapi: direct link, hf CLI and curl.
- Browser
- Download file 740 Bytes
-
https://huggingface.co/spaces/PageOrg/summaryapi/resolve/fddef45790dc11b94fb0f367f5e1ea4628ed07eb/utils/logging.py
- Command line
-
hf download hf://spaces/PageOrg/summaryapi@fddef45790dc11b94fb0f367f5e1ea4628ed07eb/utils/logging.py
-
curl -L -o logging.py https://huggingface.co/spaces/PageOrg/summaryapi/resolve/fddef45790dc11b94fb0f367f5e1ea4628ed07eb/utils/logging.py
740 Bytes
| from logging.handlers import RotatingFileHandler | |
| import logging | |
| log_file = '/.cache/app.log' | |
| # 配置 RotatingFileHandler | |
| handler = RotatingFileHandler(log_file, maxBytes=100 * 1024 * 1024, backupCount=3) # 100MG | |
| handler.setLevel(logging.INFO) | |
| handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) | |
| logger = logging.getLogger() | |
| logger.addHandler(handler) | |
| def read_last_n_logs(n, level='ERROR'): | |
| error_logs = [] | |
| with open(log_file, 'r') as file: | |
| lines = file.readlines()[-n:] | |
| # 检查每行日志的级别,只保留 ERROR 级别的日志 | |
| for line in lines: | |
| if level in line: | |
| error_logs.append(line.strip()) | |
| return error_logs | |