logging-ext2 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- logging_ext2-0.2.1/.git +1 -0
- {logging_ext2-0.2.0 → logging_ext2-0.2.1}/PKG-INFO +1 -1
- {logging_ext2-0.2.0 → logging_ext2-0.2.1}/src/logging_ext2/__about__.py +1 -1
- {logging_ext2-0.2.0 → logging_ext2-0.2.1}/src/logging_ext2/handlers.py +8 -3
- {logging_ext2-0.2.0 → logging_ext2-0.2.1}/.gitignore +0 -0
- {logging_ext2-0.2.0 → logging_ext2-0.2.1}/LICENSE +0 -0
- {logging_ext2-0.2.0 → logging_ext2-0.2.1}/README.md +0 -0
- {logging_ext2-0.2.0 → logging_ext2-0.2.1}/pyproject.toml +0 -0
- {logging_ext2-0.2.0 → logging_ext2-0.2.1}/src/logging_ext2/__init__.py +0 -0
- {logging_ext2-0.2.0 → logging_ext2-0.2.1}/src/logging_ext2/types.py +0 -0
- {logging_ext2-0.2.0 → logging_ext2-0.2.1}/tests/__init__.py +0 -0
logging_ext2-0.2.1/.git
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gitdir: ../../.git/modules/python/logging-ext2
|
@@ -24,6 +24,7 @@ class TimedRotatingFileHandler(Handler):
|
|
24
24
|
max_keep: how many files will the rotation keep
|
25
25
|
flat_keep: how many files will stay in text mod, the other (max_keep-flat_keep) will be compressed using gzip
|
26
26
|
"""
|
27
|
+
self.filepath: Path = None
|
27
28
|
self.filename = Path(filename).name
|
28
29
|
self.base_dir = Path(filename).parent
|
29
30
|
self.datetime_formatter = datetime_formatter
|
@@ -34,9 +35,9 @@ class TimedRotatingFileHandler(Handler):
|
|
34
35
|
super().__init__(level)
|
35
36
|
|
36
37
|
def init_stream(self):
|
37
|
-
filepath = self.base_dir.joinpath(
|
38
|
+
self.filepath = self.base_dir.joinpath(
|
38
39
|
f"{self.filename}.{self.get_time_str()}")
|
39
|
-
return open(filepath, "a")
|
40
|
+
return open(self.filepath, "a")
|
40
41
|
|
41
42
|
def get_time_str(self) -> str:
|
42
43
|
return datetime.datetime.now().strftime(self.datetime_formatter)
|
@@ -52,7 +53,8 @@ class TimedRotatingFileHandler(Handler):
|
|
52
53
|
return new_time_str != self.current_time_str
|
53
54
|
|
54
55
|
def do_rollover(self):
|
55
|
-
self.
|
56
|
+
if self.filepath.exists():
|
57
|
+
self.stream.close()
|
56
58
|
paths: List[Path] = [
|
57
59
|
i
|
58
60
|
for i in self.base_dir.iterdir()
|
@@ -65,6 +67,9 @@ class TimedRotatingFileHandler(Handler):
|
|
65
67
|
for to_gzip_path in paths[self.flat_keep:self.max_keep]:
|
66
68
|
# here use the system gzip command to ignore exceptions like
|
67
69
|
# permission denied or file not found
|
70
|
+
if not to_gzip_path.stat().st_size:
|
71
|
+
to_gzip_path.unlink(missing_ok=True)
|
72
|
+
continue
|
68
73
|
if to_gzip_path.suffix == ".gz":
|
69
74
|
continue
|
70
75
|
self.base_dir.joinpath(self.filename).touch()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|