Download Brain/src/log_cycle/json_handler.py from posix4e/brain: direct link, hf CLI and curl.
- Browser
- Download file 514 Bytes
-
https://huggingface.co/spaces/posix4e/brain/resolve/main/Brain/src/log_cycle/json_handler.py
- Command line
-
hf download hf://spaces/posix4e/brain/Brain/src/log_cycle/json_handler.py
-
curl -L -o json_handler.py https://huggingface.co/spaces/posix4e/brain/resolve/main/Brain/src/log_cycle/json_handler.py
514 Bytes
| import json | |
| import logging | |
| class JsonFileHandler(logging.FileHandler): | |
| def __init__(self, filename, mode="a", encoding=None, delay=False): | |
| super().__init__(filename, mode, encoding, delay) | |
| def emit(self, record): | |
| json_data = json.loads(self.format(record)) | |
| with open(self.baseFilename, "w", encoding="utf-8") as f: | |
| json.dump(json_data, f, ensure_ascii=False, indent=4) | |
| class JsonFormatter(logging.Formatter): | |
| def format(self, record): | |
| return record.msg | |