logging-ext2 0.2.4__py3-none-any.whl → 0.3.0__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.4"
4
+ __version__ = "0.3.0"
logging_ext2/handlers.py CHANGED
@@ -6,6 +6,7 @@
6
6
  import datetime
7
7
  import subprocess
8
8
  import time
9
+ from typing import List
9
10
 
10
11
  from filelock import FileLock
11
12
 
@@ -21,18 +22,19 @@ class TimedRotatingFileHandler(Handler):
21
22
  """
22
23
 
23
24
  def __init__(self, level=NOTSET, filename="log.log",
24
- datetime_formatter="%Y-%m-%d", max_keep=10, flat_keep=2):
25
+ datetime_formatter="%Y-%m-%d", max_keep=10, flat_keep=2) -> None:
25
26
  """
26
27
  params:
27
28
  max_keep: how many files will the rotation keep
28
29
  flat_keep: how many files will stay in text mod, the other (max_keep-flat_keep) will be compressed using gzip
29
30
  """
30
- self.filepath: Path = None
31
+ self.filepath: Path = None # type: ignore[assignment]
31
32
  self.filename = Path(filename).name
32
33
  self.base_dir = Path(filename).parent
33
34
  self.datetime_formatter = datetime_formatter
34
35
  self.current_time_str = self.get_time_str()
35
36
  self.stream = self.init_stream()
37
+ assert self.filepath
36
38
  self.max_keep = max_keep
37
39
  self.flat_keep = flat_keep
38
40
  super().__init__(level)
@@ -55,9 +57,10 @@ class TimedRotatingFileHandler(Handler):
55
57
  new_time_str = self.get_time_str()
56
58
  return new_time_str != self.current_time_str
57
59
 
58
- def do_rollover(self):
60
+ def do_rollover(self) -> None:
59
61
  if self.filepath.exists():
60
62
  self.stream.close()
63
+ self.stream = self.init_stream()
61
64
  paths: List[Path] = [
62
65
  i
63
66
  for i in self.base_dir.iterdir()
@@ -66,10 +69,19 @@ class TimedRotatingFileHandler(Handler):
66
69
  paths.sort(key=lambda x: x.name, reverse=True)
67
70
  to_delete: Path
68
71
  for to_delete in paths[self.max_keep:]:
72
+ if to_delete == self.filepath:
73
+ continue
69
74
  to_delete.unlink(missing_ok=True)
75
+
76
+ def gzip_file(self, paths) -> None:
77
+ """
78
+ TODO use async function to gzip file
79
+ """
70
80
  for to_gzip_path in paths[self.flat_keep:self.max_keep]:
71
81
  # here use the system gzip command to ignore exceptions like
72
82
  # permission denied or file not found
83
+ if to_gzip_path == self.filepath:
84
+ continue
73
85
  try:
74
86
  if not to_gzip_path.stat().st_size:
75
87
  to_gzip_path.unlink(missing_ok=True)
@@ -90,4 +102,3 @@ class TimedRotatingFileHandler(Handler):
90
102
  ).with_suffix(".gz"))
91
103
  cmds = ["gzip", to_gzip_path]
92
104
  subprocess.run(cmds)
93
- self.stream = self.init_stream()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: logging-ext2
3
- Version: 0.2.4
3
+ Version: 0.3.0
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=spWUlBPWMENSlVLrNMfRO_unWIWWKqZrmfbE2omj94M,121
2
+ logging_ext2/__init__.py,sha256=BA6rgdmh3z2v01cbHU1FRMsBIRV5vQjh2w9FzG2F2GY,99
3
+ logging_ext2/handlers.py,sha256=eIjll7VJHXTgsEk7Zs2Bs9UlXdsTtIOkCUC38oeydNI,3647
4
+ logging_ext2/types.py,sha256=cLjODjTgxrZEXUZzOkrFm3s6bUG3Itc_fS7KJ-MSWC8,237
5
+ logging_ext2-0.3.0.dist-info/METADATA,sha256=73KZwCVI3P-1ajyPUmBbasVGtCNPNk64DPNsj3wf0eU,1453
6
+ logging_ext2-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ logging_ext2-0.3.0.dist-info/licenses/LICENSE,sha256=RckqF9bdq7oO9RrL4iZYuXNhkIcXexbXNF2ToiaJymU,1067
8
+ logging_ext2-0.3.0.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- logging_ext2/__about__.py,sha256=-MvhEn10ANMYbo0dJNnemdwJcdTb5ZdoQzP842QKWd4,121
2
- logging_ext2/__init__.py,sha256=BA6rgdmh3z2v01cbHU1FRMsBIRV5vQjh2w9FzG2F2GY,99
3
- logging_ext2/handlers.py,sha256=xaeeJKt8mNV404XZFSImaKQie_eg0FSL-21eFnqDJ5c,3301
4
- logging_ext2/types.py,sha256=cLjODjTgxrZEXUZzOkrFm3s6bUG3Itc_fS7KJ-MSWC8,237
5
- logging_ext2-0.2.4.dist-info/METADATA,sha256=SdPhAGWpX7cGVp_D39Euh_ECEWR6eiQnmiH_rarABLk,1453
6
- logging_ext2-0.2.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- logging_ext2-0.2.4.dist-info/licenses/LICENSE,sha256=RckqF9bdq7oO9RrL4iZYuXNhkIcXexbXNF2ToiaJymU,1067
8
- logging_ext2-0.2.4.dist-info/RECORD,,