logging-ext2 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl

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/__about__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2025-present Xiang Wang <ramwin@qq.com>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- __version__ = "0.2.0"
4
+ __version__ = "0.2.1"
logging_ext2/handlers.py CHANGED
@@ -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.stream.close()
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: logging-ext2
3
- Version: 0.2.0
3
+ Version: 0.2.1
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
@@ -0,0 +1,8 @@
1
+ logging_ext2/__about__.py,sha256=mUu4qhx9EBxDtNiujiI_vqVwo8Jx3o3ULeBVbvx8RkM,121
2
+ logging_ext2/__init__.py,sha256=BA6rgdmh3z2v01cbHU1FRMsBIRV5vQjh2w9FzG2F2GY,99
3
+ logging_ext2/handlers.py,sha256=UCPKGYrOAFT5Eztv4UJa1ZMlbecjn4nqNg02jxbJXlA,2875
4
+ logging_ext2/types.py,sha256=cLjODjTgxrZEXUZzOkrFm3s6bUG3Itc_fS7KJ-MSWC8,237
5
+ logging_ext2-0.2.1.dist-info/METADATA,sha256=TIMXq6mEkBHRUvXlE7kek02kcv7YcYxWgubJUQ2oLKs,1429
6
+ logging_ext2-0.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ logging_ext2-0.2.1.dist-info/licenses/LICENSE,sha256=RckqF9bdq7oO9RrL4iZYuXNhkIcXexbXNF2ToiaJymU,1067
8
+ logging_ext2-0.2.1.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- logging_ext2/__about__.py,sha256=_5frGGck8TSRy4BEkicUdrNJZN8-umwWxzaLivX4aaU,121
2
- logging_ext2/__init__.py,sha256=BA6rgdmh3z2v01cbHU1FRMsBIRV5vQjh2w9FzG2F2GY,99
3
- logging_ext2/handlers.py,sha256=R2nsK885RWR1ItbzQmKMsYwCgsCXaHQ7NKrlA1Py_Gw,2665
4
- logging_ext2/types.py,sha256=cLjODjTgxrZEXUZzOkrFm3s6bUG3Itc_fS7KJ-MSWC8,237
5
- logging_ext2-0.2.0.dist-info/METADATA,sha256=v-q-UmYw7rz_z5E30TjUwIMsyg90z731Rdfzl105IlM,1429
6
- logging_ext2-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- logging_ext2-0.2.0.dist-info/licenses/LICENSE,sha256=RckqF9bdq7oO9RrL4iZYuXNhkIcXexbXNF2ToiaJymU,1067
8
- logging_ext2-0.2.0.dist-info/RECORD,,