-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d395e4c
commit 8e81528
Showing
7 changed files
with
221 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from .handler import MidnightRotatingFileHandler, CompressedMidnightRotatingFileHandler | ||
from .utils import rotate_file | ||
|
||
# isort: split | ||
|
||
from .config import get_logging_dict, rotate_files, inject_log_buffer | ||
from .config import load_logging_file, get_logging_dict, inject_queue_handler | ||
from .default_logfile import get_default_logfile, create_default_logfile | ||
from .queue_handler import HABAppQueueHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pathlib import Path | ||
|
||
|
||
def _get_file_name(file: Path, nr: int) -> Path: | ||
if nr < 0: | ||
raise ValueError() | ||
|
||
if nr: | ||
return file.with_name(f'{file.name:s}.{nr:d}') | ||
return file | ||
|
||
|
||
def rotate_file(file: Path, backup_count: int) -> None: | ||
if not isinstance(backup_count, int): | ||
raise TypeError() | ||
|
||
_get_file_name(file, backup_count).unlink(missing_ok=True) | ||
for i in range(backup_count - 1, -1, -1): | ||
src = _get_file_name(file, i) | ||
if not src.is_file(): | ||
continue | ||
|
||
dst = _get_file_name(file, i + 1) | ||
dst.unlink(missing_ok=True) | ||
src.rename(dst) |
Oops, something went wrong.