|
15 | 15 | import logging
|
16 | 16 | from typing import Any, TextIO
|
17 | 17 | import os
|
| 18 | +from pathlib import Path |
| 19 | + |
18 | 20 |
|
19 | 21 | import structlog
|
20 | 22 | from structlog import WriteLogger, PrintLogger
|
@@ -71,6 +73,32 @@ def configure_file_and_print_logger(file_path: str = "app.log") -> None:
|
71 | 73 | )
|
72 | 74 |
|
73 | 75 |
|
| 76 | +def configure_file_logger(file_path: str = "app.log") -> None: |
| 77 | + structlog.configure( |
| 78 | + processors=[ |
| 79 | + structlog.contextvars.merge_contextvars, |
| 80 | + structlog.processors.add_log_level, |
| 81 | + structlog.processors.StackInfoRenderer(), |
| 82 | + structlog.dev.set_exc_info, |
| 83 | + structlog.processors.CallsiteParameterAdder( |
| 84 | + [ |
| 85 | + structlog.processors.CallsiteParameter.FILENAME, |
| 86 | + structlog.processors.CallsiteParameter.FUNC_NAME, |
| 87 | + structlog.processors.CallsiteParameter.LINENO, |
| 88 | + ], |
| 89 | + ), |
| 90 | + structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S", utc=False), |
| 91 | + structlog.processors.JSONRenderer(), |
| 92 | + ], |
| 93 | + wrapper_class=structlog.make_filtering_bound_logger(logging.NOTSET), |
| 94 | + context_class=dict, |
| 95 | + logger_factory=structlog.WriteLoggerFactory( |
| 96 | + file=Path("app").with_suffix(".log").open("wt") |
| 97 | + ), |
| 98 | + cache_logger_on_first_use=False, |
| 99 | + ) |
| 100 | + |
| 101 | + |
74 | 102 | def configure_print_logger() -> None:
|
75 | 103 | structlog.configure(
|
76 | 104 | processors=[
|
|
0 commit comments