tee-logger 6.43__tar.gz → 6.45__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.
@@ -1,11 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tee-logger
3
- Version: 6.43
3
+ Version: 6.45
4
4
  Summary: A simple wrapper for python logger that also selectively tee logs to stdout
5
5
  Author-email: Yufei Pan <pan@zopyr.us>
6
- License: GPL-3.0-or-later
6
+ License-Expression: GPL-3.0-or-later
7
7
  Project-URL: Homepage, https://github.com/yufei-pan/Tee_Logger
8
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
9
8
  Classifier: Programming Language :: Python :: 3
10
9
  Classifier: Operating System :: OS Independent
11
10
  Requires-Python: >=3.6
@@ -58,12 +57,22 @@ tl = teeLogger(
58
57
  )
59
58
  ```
60
59
 
61
- Compressed logs are written in batches so they compress well, and flushed to disk:
60
+ Compressed logs are written in batches so they compress well. A batch goes to disk:
62
61
 
63
62
  - immediately for `WARNING` and above (`warning`, `error`, `critical`, `exception`, …),
64
- - otherwise at most `flush_interval` seconds (default 30) after a record is written, even if the program goes quiet.
63
+ - otherwise at most `flush_interval` seconds (default 30) after a record is logged, even if the program goes quiet, or as soon as 1 MiB of records is waiting.
65
64
 
66
- So if the process is killed (OOM, `SIGKILL`, segfault), at most the last `flush_interval` seconds of `DEBUG`/`INFO` records are lost; warnings and errors are already on disk. gzip and zstd flush mid-stream; xz and bz2 cannot, so each flush finishes the current stream and starts a new one in the same file (`xz -dc`, `bzip2 -dc`, `lzma.open`, `bz2.open` read them all). A file that is still being written may end in an unfinished stream: `zcat`/`zstd -dc` print everything and then warn about it. `flush_interval=0` flushes every record, which costs a lot of compression (gzip/zstd files about twice as large).
65
+ So if the process is killed (OOM, `SIGKILL`, segfault), at most the last `flush_interval` seconds of `DEBUG`/`INFO` records are lost; warnings and errors are already on disk. Each batch is written as a whole gzip member (xz or bz2 stream, zstd frame), and `zcat`, `xz -dc`, `bzip2 -dc`, `zstd -dc` and Python's readers read the members back as one file. So a log stays readable however its writers end, including when a restarted run or a second process with the same `programName` appends to the same day's file.
66
+
67
+ Known limitations (details in [docs/limitations.md](docs/limitations.md)):
68
+
69
+ - Each batch is compressed on its own, so frequent flushes make gzip and zstd logs larger: about +40% when one record in ten is `WARNING` or above, three times with `flush_interval=0`. Waiting records are written before each fork (Python 3.7+), which adds a member per fork. xz and bz2 are not affected.
70
+ - A batch that cannot be written (a full disk) is lost, and each failed write is reported on stderr.
71
+ - `binary_mode=False` does not apply to compressed logs.
72
+ - If the background flusher cannot be started (the process is out of threads), it is not tried again; records then reach disk on `WARNING` and above, on a later record, and at exit.
73
+ - On Python 3.6 and 3.7, when records fall back to stderr, another thread's output can land inside a record's line.
74
+ - A forked child that leaves with `os._exit` or is killed loses the records it logged since its last write; so can the workers of a Pool ended by `terminate()` (its `with` block). Workers that end normally do not.
75
+ - On Python 3.6, records waiting at a fork are not written first: a daemon whose parent leaves with `os._exit` loses its startup lines. And, as with any 3.6 logging handler, a child forked while another thread is writing the log can hang at its first record.
67
76
 
68
77
  Disable file logging:
69
78
 
@@ -82,8 +91,8 @@ tl = teeLogger(noLog=True)
82
91
  | `callerStackDepth` | `-1` | Auto-resolve direct caller; use `0+` for manual stack offset |
83
92
  | `in_place_compression` | `None` | `zstd`/`zst`, `xz`/`lzma`, `gzip`, `bz2`, or `True` (first available, in that order) |
84
93
  | `compression_level` | backend default | gzip/bz2 `compresslevel`, xz `preset`, zstd `level` (xz presets 7–9 need hundreds of MB of RAM) |
85
- | `flush_interval` | `30` | Max seconds before compressed records reach disk; `0` = every record, `float('inf')` = only on WARNING+ and at close |
86
- | `binary_mode` | `True` | Binary append mode for log files |
94
+ | `flush_interval` | `30` | Max seconds before compressed records reach disk; `0` = every record, `float('inf')` = only on WARNING+, per 1 MiB of records, and at close |
95
+ | `binary_mode` | `True` | Binary append mode for uncompressed log files; compressed ones are always binary |
87
96
  | `compressLogAfterMonths` | `2` | Archive day-folders older than N months (`0` = off) |
88
97
  | `deleteLogAfterYears` | `2` | Delete day-folders older than N years (`0` = off) |
89
98
  | `noLog` | `False` | Disable file logging |
@@ -140,9 +149,9 @@ On initialization and at each midnight rollover, `{programName}_log/` is scanned
140
149
  1. **Delete** folders and archives older than `deleteLogAfterYears`
141
150
  2. **Compress** folders older than `compressLogAfterMonths` to `.tar.xz`
142
151
 
143
- Folders with a file modified in the last 24 hours are left alone, in case another process is still writing there. The work runs in a background thread; the program exits only after an archive in progress is finished. `cleanup_old_logs()` runs the same maintenance synchronously.
152
+ Folders with a file modified in the last 24 hours are left alone, in case another process is still writing there. A folder named like a date that is not one (`2020-13-45`) is skipped, with a message on stderr. The work runs in a background thread; the program exits only after an archive in progress is finished. `cleanup_old_logs()` runs the same maintenance synchronously.
144
153
 
145
- Compression uses system `tar`+`xz` when available, otherwise Python's `tarfile`. It is safe against crashes and concurrent cleanups: the folder is first renamed to `YYYY-MM-DD.compressing-<pid>/`, the archive is written to a temporary file and renamed into place, and only then is the folder deleted. If archiving fails, the folder is put back; a claim left by a crashed process is picked up again after 24 hours.
154
+ Compression uses system `tar`+`xz` when available, otherwise Python's `tarfile`. It is safe against crashes and concurrent cleanups: the folder is first renamed to `YYYY-MM-DD.compressing-<pid>/`, the archive is written to a temporary file, flushed to disk (fsync) and renamed into place, the directory is flushed too, and only then is the folder deleted. If archiving or the flush of the archive fails, the folder is put back; if the directory flush fails, the claim stays with the logs in it; a claim left by a crashed process is picked up again after 24 hours.
146
155
 
147
156
  ## API reference
148
157
 
@@ -184,6 +193,28 @@ python src/Tee_Logger.py -V
184
193
 
185
194
  CI runs on Python 3.9, 3.11, 3.12, and 3.14, plus 3.6 in a `python:3.6` container.
186
195
 
196
+ ## Upgrading to 6.45 from 6.44
197
+
198
+ - Packaging only: the license is declared as the SPDX expression `GPL-3.0-or-later` (no license classifier), so building from source needs setuptools 77.0.1 or later, which needs Python 3.9 or later. The code is unchanged. pip 9 (EL7, EL8) still installs the wheel; its `pip show` prints `License: None`, as it cannot read the new field.
199
+ - Compressing a day's logs flushes the archive to disk before it is renamed into place, and the log directory after, before the day's logs are deleted. Before, a crash or hard reset before the kernel wrote the archive back, often tens of seconds after a compression, could leave an empty or short `.tar.xz` and no logs (possible on XFS, and on ext4 for a new name). Where the file system cannot sync (some FUSE mounts), or the directory cannot be opened for it (a mode 0300 directory), or on Windows, the flush is skipped, as before. A disk that refuses the flush keeps the logs and reports `Failed to sync` or `Failed to compress folder` on stderr; a later cleanup tries again.
200
+
201
+ ## Upgrading to 6.44 from 6.43
202
+
203
+ - Compressed logs are written as one whole gzip member (xz or bz2 stream, zstd frame) per flush. In 6.43 a gzip or zstd log could not be read past the point where a run was killed, once a restarted run or a second process with the same `programName` appended to the same day's file; such a file now stays readable. The cost: gzip and zstd logs with frequent `WARNING`+ records, or with `flush_interval=0`, are larger (see the limitations above). xz and bz2 logs are unchanged.
204
+ - A compressed batch that cannot be written (a full disk) is dropped and reported each time it fails; a partial write is cut back so later records stay readable.
205
+ - `binary_mode=False` no longer affects compressed logs.
206
+ - `teeLogger.GZipFileHandler`, `BZ2FileHandler`, `XZFileHandler` and `ZSTDFileHandler` are gone; one internal handler writes all four formats. `teeLogger.BinFileHandler` stays.
207
+ - `flush_interval` is taken with `float()`: `'30'` now means 30 seconds (6.43 raised `TypeError`), and NaN means "only on `WARNING` and above and at close" (6.43 raised `ValueError`).
208
+ - Console lines go through `print()` again, still with each whole line in one write, so a program that replaces `builtins.print` sees them.
209
+ - At midnight the log handler switches to the new day's file itself. A signal handler that logs while its thread holds `logging`'s own lock can no longer deadlock with another thread's midnight switch.
210
+ - A `logging.FileHandler` you attach yourself to the logger named `programName` is no longer closed when another `teeLogger` of that name is made.
211
+ - If the background flusher cannot be started, it is not tried again (6.43 retried once per interval).
212
+ - Compressed records still waiting when the process forks are written before the fork (Python 3.7+; 3.6 has no at-fork hooks), so a daemon's parent leaving with `os._exit` no longer drops them. A child no longer writes the parent's waiting records a second time, and starts a flush timer of its own. A multiprocessing worker writes its last records when it ends, also when it imports Tee_Logger only once it runs. 6.43 duplicated such records, or corrupted gzip and zstd logs, and lost a worker's last ones. A program that forks often while records wait gets one more compressed member per fork. A child forked while another thread was switching to the new day's file no longer hangs on that switch's lock at its own next midnight (on 3.6, see the limitation above).
213
+ - The `tee*` methods log to the file before they print, so a console that fails (`prog | head -1`) no longer loses the record from the file; the error is still raised.
214
+ - A compression level the backend refuses is reported by name (`gzip refuses compression_level 10 (...)`).
215
+ - A day-folder named like a date that is not one (`2020-13-45`) is skipped with a message, instead of being aged by its mtime.
216
+ - The stderr fallback uses the stdlib `StreamHandler`; see the 3.6/3.7 limitation above.
217
+
187
218
  ## Upgrading to 6.43 from 6.42
188
219
 
189
220
  - When a compressed log file will use it (`in_place_compression` set, `noLog` off, and a log directory other than `/dev/null`, `/dev/stdout` or `/dev/stderr`), `flush_interval` must be a number: NaN raises `ValueError` and a non-number (`None`, `'30'`) raises `TypeError` when the logger is made, and the value is kept as a float. 6.42 accepted them: `None` and `'30'` then printed a logging error for every record below WARNING, and NaN kept its flusher thread busy on a CPU core while records reached disk only on WARNING and above and at close. Otherwise the value is still not checked.
@@ -41,12 +41,22 @@ tl = teeLogger(
41
41
  )
42
42
  ```
43
43
 
44
- Compressed logs are written in batches so they compress well, and flushed to disk:
44
+ Compressed logs are written in batches so they compress well. A batch goes to disk:
45
45
 
46
46
  - immediately for `WARNING` and above (`warning`, `error`, `critical`, `exception`, …),
47
- - otherwise at most `flush_interval` seconds (default 30) after a record is written, even if the program goes quiet.
47
+ - otherwise at most `flush_interval` seconds (default 30) after a record is logged, even if the program goes quiet, or as soon as 1 MiB of records is waiting.
48
48
 
49
- So if the process is killed (OOM, `SIGKILL`, segfault), at most the last `flush_interval` seconds of `DEBUG`/`INFO` records are lost; warnings and errors are already on disk. gzip and zstd flush mid-stream; xz and bz2 cannot, so each flush finishes the current stream and starts a new one in the same file (`xz -dc`, `bzip2 -dc`, `lzma.open`, `bz2.open` read them all). A file that is still being written may end in an unfinished stream: `zcat`/`zstd -dc` print everything and then warn about it. `flush_interval=0` flushes every record, which costs a lot of compression (gzip/zstd files about twice as large).
49
+ So if the process is killed (OOM, `SIGKILL`, segfault), at most the last `flush_interval` seconds of `DEBUG`/`INFO` records are lost; warnings and errors are already on disk. Each batch is written as a whole gzip member (xz or bz2 stream, zstd frame), and `zcat`, `xz -dc`, `bzip2 -dc`, `zstd -dc` and Python's readers read the members back as one file. So a log stays readable however its writers end, including when a restarted run or a second process with the same `programName` appends to the same day's file.
50
+
51
+ Known limitations (details in [docs/limitations.md](docs/limitations.md)):
52
+
53
+ - Each batch is compressed on its own, so frequent flushes make gzip and zstd logs larger: about +40% when one record in ten is `WARNING` or above, three times with `flush_interval=0`. Waiting records are written before each fork (Python 3.7+), which adds a member per fork. xz and bz2 are not affected.
54
+ - A batch that cannot be written (a full disk) is lost, and each failed write is reported on stderr.
55
+ - `binary_mode=False` does not apply to compressed logs.
56
+ - If the background flusher cannot be started (the process is out of threads), it is not tried again; records then reach disk on `WARNING` and above, on a later record, and at exit.
57
+ - On Python 3.6 and 3.7, when records fall back to stderr, another thread's output can land inside a record's line.
58
+ - A forked child that leaves with `os._exit` or is killed loses the records it logged since its last write; so can the workers of a Pool ended by `terminate()` (its `with` block). Workers that end normally do not.
59
+ - On Python 3.6, records waiting at a fork are not written first: a daemon whose parent leaves with `os._exit` loses its startup lines. And, as with any 3.6 logging handler, a child forked while another thread is writing the log can hang at its first record.
50
60
 
51
61
  Disable file logging:
52
62
 
@@ -65,8 +75,8 @@ tl = teeLogger(noLog=True)
65
75
  | `callerStackDepth` | `-1` | Auto-resolve direct caller; use `0+` for manual stack offset |
66
76
  | `in_place_compression` | `None` | `zstd`/`zst`, `xz`/`lzma`, `gzip`, `bz2`, or `True` (first available, in that order) |
67
77
  | `compression_level` | backend default | gzip/bz2 `compresslevel`, xz `preset`, zstd `level` (xz presets 7–9 need hundreds of MB of RAM) |
68
- | `flush_interval` | `30` | Max seconds before compressed records reach disk; `0` = every record, `float('inf')` = only on WARNING+ and at close |
69
- | `binary_mode` | `True` | Binary append mode for log files |
78
+ | `flush_interval` | `30` | Max seconds before compressed records reach disk; `0` = every record, `float('inf')` = only on WARNING+, per 1 MiB of records, and at close |
79
+ | `binary_mode` | `True` | Binary append mode for uncompressed log files; compressed ones are always binary |
70
80
  | `compressLogAfterMonths` | `2` | Archive day-folders older than N months (`0` = off) |
71
81
  | `deleteLogAfterYears` | `2` | Delete day-folders older than N years (`0` = off) |
72
82
  | `noLog` | `False` | Disable file logging |
@@ -123,9 +133,9 @@ On initialization and at each midnight rollover, `{programName}_log/` is scanned
123
133
  1. **Delete** folders and archives older than `deleteLogAfterYears`
124
134
  2. **Compress** folders older than `compressLogAfterMonths` to `.tar.xz`
125
135
 
126
- Folders with a file modified in the last 24 hours are left alone, in case another process is still writing there. The work runs in a background thread; the program exits only after an archive in progress is finished. `cleanup_old_logs()` runs the same maintenance synchronously.
136
+ Folders with a file modified in the last 24 hours are left alone, in case another process is still writing there. A folder named like a date that is not one (`2020-13-45`) is skipped, with a message on stderr. The work runs in a background thread; the program exits only after an archive in progress is finished. `cleanup_old_logs()` runs the same maintenance synchronously.
127
137
 
128
- Compression uses system `tar`+`xz` when available, otherwise Python's `tarfile`. It is safe against crashes and concurrent cleanups: the folder is first renamed to `YYYY-MM-DD.compressing-<pid>/`, the archive is written to a temporary file and renamed into place, and only then is the folder deleted. If archiving fails, the folder is put back; a claim left by a crashed process is picked up again after 24 hours.
138
+ Compression uses system `tar`+`xz` when available, otherwise Python's `tarfile`. It is safe against crashes and concurrent cleanups: the folder is first renamed to `YYYY-MM-DD.compressing-<pid>/`, the archive is written to a temporary file, flushed to disk (fsync) and renamed into place, the directory is flushed too, and only then is the folder deleted. If archiving or the flush of the archive fails, the folder is put back; if the directory flush fails, the claim stays with the logs in it; a claim left by a crashed process is picked up again after 24 hours.
129
139
 
130
140
  ## API reference
131
141
 
@@ -167,6 +177,28 @@ python src/Tee_Logger.py -V
167
177
 
168
178
  CI runs on Python 3.9, 3.11, 3.12, and 3.14, plus 3.6 in a `python:3.6` container.
169
179
 
180
+ ## Upgrading to 6.45 from 6.44
181
+
182
+ - Packaging only: the license is declared as the SPDX expression `GPL-3.0-or-later` (no license classifier), so building from source needs setuptools 77.0.1 or later, which needs Python 3.9 or later. The code is unchanged. pip 9 (EL7, EL8) still installs the wheel; its `pip show` prints `License: None`, as it cannot read the new field.
183
+ - Compressing a day's logs flushes the archive to disk before it is renamed into place, and the log directory after, before the day's logs are deleted. Before, a crash or hard reset before the kernel wrote the archive back, often tens of seconds after a compression, could leave an empty or short `.tar.xz` and no logs (possible on XFS, and on ext4 for a new name). Where the file system cannot sync (some FUSE mounts), or the directory cannot be opened for it (a mode 0300 directory), or on Windows, the flush is skipped, as before. A disk that refuses the flush keeps the logs and reports `Failed to sync` or `Failed to compress folder` on stderr; a later cleanup tries again.
184
+
185
+ ## Upgrading to 6.44 from 6.43
186
+
187
+ - Compressed logs are written as one whole gzip member (xz or bz2 stream, zstd frame) per flush. In 6.43 a gzip or zstd log could not be read past the point where a run was killed, once a restarted run or a second process with the same `programName` appended to the same day's file; such a file now stays readable. The cost: gzip and zstd logs with frequent `WARNING`+ records, or with `flush_interval=0`, are larger (see the limitations above). xz and bz2 logs are unchanged.
188
+ - A compressed batch that cannot be written (a full disk) is dropped and reported each time it fails; a partial write is cut back so later records stay readable.
189
+ - `binary_mode=False` no longer affects compressed logs.
190
+ - `teeLogger.GZipFileHandler`, `BZ2FileHandler`, `XZFileHandler` and `ZSTDFileHandler` are gone; one internal handler writes all four formats. `teeLogger.BinFileHandler` stays.
191
+ - `flush_interval` is taken with `float()`: `'30'` now means 30 seconds (6.43 raised `TypeError`), and NaN means "only on `WARNING` and above and at close" (6.43 raised `ValueError`).
192
+ - Console lines go through `print()` again, still with each whole line in one write, so a program that replaces `builtins.print` sees them.
193
+ - At midnight the log handler switches to the new day's file itself. A signal handler that logs while its thread holds `logging`'s own lock can no longer deadlock with another thread's midnight switch.
194
+ - A `logging.FileHandler` you attach yourself to the logger named `programName` is no longer closed when another `teeLogger` of that name is made.
195
+ - If the background flusher cannot be started, it is not tried again (6.43 retried once per interval).
196
+ - Compressed records still waiting when the process forks are written before the fork (Python 3.7+; 3.6 has no at-fork hooks), so a daemon's parent leaving with `os._exit` no longer drops them. A child no longer writes the parent's waiting records a second time, and starts a flush timer of its own. A multiprocessing worker writes its last records when it ends, also when it imports Tee_Logger only once it runs. 6.43 duplicated such records, or corrupted gzip and zstd logs, and lost a worker's last ones. A program that forks often while records wait gets one more compressed member per fork. A child forked while another thread was switching to the new day's file no longer hangs on that switch's lock at its own next midnight (on 3.6, see the limitation above).
197
+ - The `tee*` methods log to the file before they print, so a console that fails (`prog | head -1`) no longer loses the record from the file; the error is still raised.
198
+ - A compression level the backend refuses is reported by name (`gzip refuses compression_level 10 (...)`).
199
+ - A day-folder named like a date that is not one (`2020-13-45`) is skipped with a message, instead of being aged by its mtime.
200
+ - The stderr fallback uses the stdlib `StreamHandler`; see the 3.6/3.7 limitation above.
201
+
170
202
  ## Upgrading to 6.43 from 6.42
171
203
 
172
204
  - When a compressed log file will use it (`in_place_compression` set, `noLog` off, and a log directory other than `/dev/null`, `/dev/stdout` or `/dev/stderr`), `flush_interval` must be a number: NaN raises `ValueError` and a non-number (`None`, `'30'`) raises `TypeError` when the logger is made, and the value is kept as a float. 6.42 accepted them: `None` and `'30'` then printed a logging error for every record below WARNING, and NaN kept its flusher thread busy on a CPU core while records reached disk only on WARNING and above and at close. Otherwise the value is still not checked.
@@ -1,5 +1,7 @@
1
1
  [build-system]
2
- requires = ["setuptools>=61"]
2
+ # 77.0.1 is the first setuptools on PyPI that accepts `license` as an SPDX string (PEP 639):
3
+ # 76.1.0 rejects the string, and 77.0.0 is not on PyPI.
4
+ requires = ["setuptools>=77.0.1"]
3
5
  build-backend = "setuptools.build_meta"
4
6
 
5
7
  [project]
@@ -13,11 +15,10 @@ authors = [
13
15
  { name = "Yufei Pan", email = "pan@zopyr.us" }
14
16
  ]
15
17
  classifiers = [
16
- "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
17
18
  "Programming Language :: Python :: 3",
18
19
  "Operating System :: OS Independent"
19
20
  ]
20
- license = {text = "GPL-3.0-or-later"}
21
+ license = "GPL-3.0-or-later"
21
22
 
22
23
  [project.urls]
23
24
  "Homepage" = "https://github.com/yufei-pan/Tee_Logger"