logging-ext2 0.2.1__tar.gz → 0.2.3__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 → logging_ext2-0.2.3}/PKG-INFO +2 -1
- {logging_ext2-0.2.1 → logging_ext2-0.2.3}/pyproject.toml +1 -1
- {logging_ext2-0.2.1 → logging_ext2-0.2.3}/src/logging_ext2/__about__.py +1 -1
- {logging_ext2-0.2.1 → logging_ext2-0.2.3}/src/logging_ext2/handlers.py +20 -9
- {logging_ext2-0.2.1 → logging_ext2-0.2.3}/tests/__init__.py +2 -2
- {logging_ext2-0.2.1 → logging_ext2-0.2.3}/.git +0 -0
- {logging_ext2-0.2.1 → logging_ext2-0.2.3}/.gitignore +0 -0
- {logging_ext2-0.2.1 → logging_ext2-0.2.3}/LICENSE +0 -0
- {logging_ext2-0.2.1 → logging_ext2-0.2.3}/README.md +0 -0
- {logging_ext2-0.2.1 → logging_ext2-0.2.3}/src/logging_ext2/__init__.py +0 -0
- {logging_ext2-0.2.1 → logging_ext2-0.2.3}/src/logging_ext2/types.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: logging-ext2
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.3
|
4
4
|
Summary: extend python logging library
|
5
5
|
Project-URL: Documentation, https://github.com/ramwin/logging-ext#readme
|
6
6
|
Project-URL: Issues, https://github.com/ramwin/logging-ext/issues
|
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
18
18
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
19
19
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
20
20
|
Requires-Python: >=3.8
|
21
|
+
Requires-Dist: filelock
|
21
22
|
Description-Content-Type: text/markdown
|
22
23
|
|
23
24
|
# logging-ext2
|
@@ -24,7 +24,7 @@ classifiers = [
|
|
24
24
|
"Programming Language :: Python :: Implementation :: CPython",
|
25
25
|
"Programming Language :: Python :: Implementation :: PyPy",
|
26
26
|
]
|
27
|
-
dependencies = []
|
27
|
+
dependencies = ["filelock"]
|
28
28
|
|
29
29
|
[project.urls]
|
30
30
|
Documentation = "https://github.com/ramwin/logging-ext#readme"
|
@@ -5,6 +5,9 @@
|
|
5
5
|
|
6
6
|
import datetime
|
7
7
|
import subprocess
|
8
|
+
import time
|
9
|
+
|
10
|
+
from filelock import FileLock
|
8
11
|
|
9
12
|
from logging import Handler, NOTSET
|
10
13
|
from pathlib import Path
|
@@ -67,16 +70,24 @@ class TimedRotatingFileHandler(Handler):
|
|
67
70
|
for to_gzip_path in paths[self.flat_keep:self.max_keep]:
|
68
71
|
# here use the system gzip command to ignore exceptions like
|
69
72
|
# permission denied or file not found
|
70
|
-
|
71
|
-
to_gzip_path.
|
73
|
+
try:
|
74
|
+
if not to_gzip_path.stat().st_size:
|
75
|
+
to_gzip_path.unlink(missing_ok=True)
|
76
|
+
continue
|
77
|
+
except FileNotFoundError:
|
72
78
|
continue
|
73
79
|
if to_gzip_path.suffix == ".gz":
|
74
80
|
continue
|
75
|
-
self.base_dir.joinpath(self.filename)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
lock_path = self.base_dir.joinpath(self.filename)
|
82
|
+
lock_path.touch()
|
83
|
+
with FileLock(lock_path, timeout=10):
|
84
|
+
target_file = to_gzip_path.parent.joinpath(
|
85
|
+
to_gzip_path.name + ".gz"
|
86
|
+
)
|
87
|
+
if target_file.exists():
|
88
|
+
target_file.rename(target_file.parent.joinpath(
|
89
|
+
target_file.stem + "_" + str(time.time())
|
90
|
+
).with_suffix(".gz"))
|
91
|
+
cmds = ["gzip", to_gzip_path]
|
92
|
+
subprocess.run(cmds)
|
82
93
|
self.stream = self.init_stream()
|
@@ -15,7 +15,7 @@ class Test(unittest.TestCase):
|
|
15
15
|
handlera = TimedRotatingFileHandler(
|
16
16
|
filename="tests/info.log",
|
17
17
|
datetime_formatter="%Y-%m-%d_%H:%M:%S",
|
18
|
-
max_keep=
|
18
|
+
max_keep=20, flat_keep=2)
|
19
19
|
loggera.addHandler(logging.StreamHandler())
|
20
20
|
loggera.addHandler(handlera)
|
21
21
|
loggera.setLevel(logging.INFO)
|
@@ -25,7 +25,7 @@ class Test(unittest.TestCase):
|
|
25
25
|
loggerb.addHandler(TimedRotatingFileHandler(
|
26
26
|
filename="tests/info.log",
|
27
27
|
datetime_formatter="%Y-%m-%d_%H:%M:%S",
|
28
|
-
max_keep=
|
28
|
+
max_keep=20, flat_keep=2))
|
29
29
|
loggerb.addHandler(logging.StreamHandler())
|
30
30
|
loggerb.setLevel(logging.INFO)
|
31
31
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|