feat(serverlibrary): add option to trunctate logfiles
This commit is contained in:
1 parent
359f64df8e
commit
082bca7828
1 file changed
+7
-2
@@ -53,7 +53,10 @@ LOG_LEVELS = {
|
||||
|
||||
|
||||
def setup_logging(
|
||||
log_level: str = "INFO", logfile: str | None = None, no_date: bool = True
|
||||
log_level: str = "INFO",
|
||||
logfile: str | None = None,
|
||||
no_date: bool = True,
|
||||
new_file: bool = False,
|
||||
) -> None:
|
||||
logging.addLevelName(TRACE, "TRACE")
|
||||
|
||||
@@ -94,7 +97,9 @@ def setup_logging(
|
||||
logfile_dir.mkdir(exist_ok=True, parents=True)
|
||||
logfile_data = logfile_dir / final_name
|
||||
|
||||
file_handler = logging.FileHandler(logfile_data, encoding="utf-8")
|
||||
file_handler = logging.FileHandler(
|
||||
logfile_data, mode="w" if new_file else "a", encoding="utf-8"
|
||||
)
|
||||
file_handler.setFormatter(file_formatter)
|
||||
file_handler.setLevel(TRACE)
|
||||
|
||||
|
||||
Reference in new issue
Block a user