Skip to content

Commit 9b7d8e9

Browse files
Git rid of some, but not all, PyCharm inspection disables.
Other general cleanup.
1 parent 1515b21 commit 9b7d8e9

File tree

10 files changed

+52
-59
lines changed

10 files changed

+52
-59
lines changed

.markdownlint.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"MD013": false,
3+
"MD046": false
4+
}

.vscode/settings.json

+8
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,25 @@
1919
"concat",
2020
"CREAT",
2121
"datetime",
22+
"gunicorn",
23+
"gzipped",
2224
"Journyx",
25+
"kwarg",
26+
"kwargs",
2327
"levelname",
28+
"logfile",
29+
"logfile's",
2430
"logfiles",
2531
"maxsplit",
2632
"multiprocess",
2733
"portalocker",
34+
"POSIX",
2835
"pychecker",
2936
"pycodestyle",
3037
"pydoc",
3138
"Pyflakes",
3239
"Pylint",
40+
"pypi",
3341
"pywin",
3442
"queuify",
3543
"stresstest",

CHANGELOG.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
- 0.9.23:
44
- Begin requiring Python 3.6 or higher.
55
- Implements a `ConcurrentTimedRotatingFileHandler` class which provides both time and/or size
6-
based rotation. See the [README.md](./README.md#time-based-rotation-settings) for details.
6+
based rotation. See the [README.md](./README.md#time-based-rotation-settings) for details.
7+
- Fix #56 - don't fail when setting `owner` on Windows, though it will have no effect.
78

89
- 0.9.22:
910
- Fix Python 2.7 compatibility (yet again)
10-
- Important note: this is the FINAL release which will support Python 2.7.
11-
Future versions will support Python 3.6+ only.
11+
- Important note: this is the FINAL release which will support Python 2.7.
12+
Future versions will support Python 3.6+ only.
1213

1314
- 0.9.21:
1415
- Added new optional parameter "lock_file_directory"
@@ -17,7 +18,7 @@
1718
- Useful when the log files reside in a cloud synced folder like Dropbox, Google Drive,
1819
OneDrive, etc. Sometimes these do not work correctly with the lock files.
1920
- Fix not replacing the last file (greatest backup number) when rotating. Thanks tzongw.
20-
- <https://github.com/Preston-Landers/concurrent-log-handler/pull/52>
21+
- <https://github.com/Preston-Landers/concurrent-log-handler/pull/52>
2122
- Add support for "namer" function to customize the naming of rotated files. Thanks @dashedman.
2223
- Enhanced test suite using tox and pytest.
2324

README.md

+27-33
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ if desired. Both Windows and POSIX systems are supported. An optional threaded
88
queue logging handler is provided to perform logging in the background.
99

1010
This is a fork of Lowell Alleman's ConcurrentLogHandler 0.9.1 which fixes
11-
a hanging/deadlocking problem. See this:
12-
13-
https://bugs.launchpad.net/python-concurrent-log-handler/+bug/1265150
11+
a hanging/deadlocking problem. [See this](https://bugs.launchpad.net/python-concurrent-log-handler/+bug/1265150).
1412

1513
Summary of other changes:
1614

1715
* New: requires Python 3.6 or higher.
18-
* If you require support for Python 2.7, use version
19-
[0.9.22](https://github.com/Preston-Landers/concurrent-log-handler/releases/tag/0.9.22).
16+
* If you require support for Python 2.7, use version
17+
[0.9.22](https://github.com/Preston-Landers/concurrent-log-handler/releases/tag/0.9.22).
2018
* Renamed package to `concurrent_log_handler` (abbreviated CLH in this file.)
2119
* Provide `use_gzip` option to compress rotated logs
2220
* Support for Windows
@@ -46,7 +44,7 @@ However, this is not the only way to achieve shared logging from multiple proces
4644
centralize logging by using cloud logging services like Azure Log Monitor, Logstash, etc. Or you can
4745
implement your own remote logging server as shown here:
4846

49-
https://docs.python.org/3/howto/logging-cookbook.html#sending-and-receiving-logging-events-across-a-network
47+
[Logging cookbook: network](https://docs.python.org/3/howto/logging-cookbook.html#sending-and-receiving-logging-events-across-a-network)
5048

5149
Concurrent-Log-Handler includes a QueueHandler and QueueListener implementation that can be used to
5250
perform logging in the background asynchronously, so the thread or process making the log statement doesn't have
@@ -80,31 +78,27 @@ If installing from source, use the following command:
8078

8179
If you plan to modify the code, you should follow this procedure:
8280

83-
- Clone the repository
84-
- Create a virtual environment (`venv`) and activate it.
85-
- Install the package in editable mode with the [dev] option:
86-
87-
`pip install -e .[dev]`
88-
89-
- Run the tests:
81+
* Clone the repository
82+
* Create a virtual environment (`venv`) and activate it.
83+
* Install the package in editable mode with the [dev] option: `pip install -e .[dev]`
9084

91-
`tox` or run `pytest` directly.
85+
* Run the tests: `tox` or run `pytest` directly.
9286

9387
Or manually run a single pass of the stress test with specific options:
9488

95-
```
96-
python tests/stresstest.py --help
97-
python tests/stresstest.py --gzip --num-processes 12 --log-calls=5000
89+
```shell
90+
python tests/stresstest.py --help
91+
python tests/stresstest.py --gzip --num-processes 12 --log-calls=5000
9892
```
9993

100-
- To build a Python "wheel" for distribution, use the following:
94+
* To build a Python "wheel" for distribution, use the following:
10195

10296
```shell
103-
python setup.py clean --all build sdist bdist_wheel
104-
# Copy the .whl file from under the "dist" folder
105-
# or upload with twine:
106-
pip install twine
107-
twine upload dist/concurrent-log-handler-0.9.23.tar.gz dist/concurrent_log_handler-0.9.23-py3-none-any.whl
97+
python setup.py clean --all build sdist bdist_wheel
98+
# Copy the .whl file from under the "dist" folder
99+
# or upload with twine:
100+
pip install twine
101+
twine upload dist/concurrent-log-handler-0.9.23.tar.gz dist/concurrent_log_handler-0.9.23-py3-none-any.whl
108102
```
109103

110104
### Important Requirements
@@ -122,14 +116,14 @@ these requirements:
122116
its OWN instance of the handler (`ConcurrentRotatingFileHandler`). The child target function
123117
should call code that initializes a new CLH instance.
124118

125-
* This requirement does not apply to threads within a given process. Different threads within a
126-
process can use the same CLH instance. Thread locking is handled automatically.
119+
* This requirement does not apply to threads within a given process. Different threads within a
120+
process can use the same CLH instance. Thread locking is handled automatically.
127121

128-
* This also does not apply to `fork()` based child processes such as gunicorn --preload.
129-
Child processes of a fork() call should be able to inherit the CLH object instance.
122+
* This also does not apply to `fork()` based child processes such as gunicorn --preload.
123+
Child processes of a fork() call should be able to inherit the CLH object instance.
130124

131-
* This limitation exists because the CLH object can't be serialized, passed over a network or
132-
pipe, and reconstituted at the other end.
125+
* This limitation exists because the CLH object can't be serialized, passed over a network or
126+
pipe, and reconstituted at the other end.
133127

134128
* It is important that every process or thread writing to a given logfile must all use the same
135129
settings, especially related to file rotation. Also do not attempt to mix different handler
@@ -180,7 +174,7 @@ multiple hosts works due to the use of file locking on the log file. Note that w
180174
logging feature, currently there is no way for the caller to know when the logging statement
181175
completed (no "Promise" or "Future" object is returned).
182176

183-
https://docs.python.org/3/library/logging.handlers.html#queuehandler
177+
[QueueHandler](https://docs.python.org/3/library/logging.handlers.html#queuehandler)
184178

185179
### Configuration
186180

@@ -202,7 +196,7 @@ Please note that Python 3.7 and higher accepts keyword arguments (kwargs) in a l
202196
config file, but earlier versions of Python only accept positional args.
203197

204198
Note: you must have an `import concurrent_log_handler` before you call fileConfig(). For
205-
more information see http://docs.python.org/lib/logging-config-fileformat.html
199+
more information see Python docs on [log file formats](http://docs.python.org/lib/logging-config-fileformat.html)
206200

207201
### Limitations
208202

@@ -237,8 +231,8 @@ order for this to work, each process writing to the log must have access to the
237231
lock file location, even if they are running on different hosts.
238232

239233
You can set the `namer` attribute of the handler to customize the naming of the rotated files,
240-
in line with the `BaseRotatingHandler` class. See the Python docs for more details:
241-
https://docs.python.org/3.11/library/logging.handlers.html#logging.handlers.BaseRotatingHandler.namer
234+
in line with the `BaseRotatingHandler` class. See the Python docs for
235+
[more details](https://docs.python.org/3.11/library/logging.handlers.html#logging.handlers.BaseRotatingHandler.namer).
242236

243237
### Line Endings
244238

src/concurrent_log_handler/__init__.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
from contextlib import contextmanager
6464
from logging.handlers import BaseRotatingHandler, TimedRotatingFileHandler
6565

66-
# noinspection PyPackageRequirements
6766
from portalocker import LOCK_EX, lock, unlock
6867

6968
from concurrent_log_handler.__version__ import __author__, __version__ # noqa: F401
@@ -77,7 +76,6 @@
7776
# Random numbers for rotation temp file names, using secrets module if available (Python 3.6).
7877
# Otherwise use `random.SystemRandom` if available, then fall back on `random.Random`.
7978
try:
80-
# noinspection PyPackageRequirements,PyCompatibility
8179
from secrets import randbits
8280
except ImportError:
8381
import random
@@ -233,9 +231,7 @@ def __init__( # noqa: PLR0913
233231
self.terminator = terminator or "\n"
234232

235233
if owner and has_chown and pwd and grp:
236-
# noinspection PyUnresolvedReferences
237234
self._set_uid = pwd.getpwnam(self.owner[0]).pw_uid
238-
# noinspection PyUnresolvedReferences
239235
self._set_gid = grp.getgrnam(self.owner[1]).gr_gid
240236

241237
self.lockFilename = self.getLockFilename(lock_file_directory)
@@ -323,7 +319,6 @@ def do_open(self, mode=None):
323319
mode = self.mode
324320

325321
with self._alter_umask():
326-
# noinspection PyArgumentList
327322
stream = open(
328323
self.baseFilename,
329324
mode=mode,
@@ -381,7 +376,6 @@ def emit(self, record):
381376
This also does the formatting *before* locks are obtained, in case the format itself does
382377
logging calls from within. Rollover also occurs while the lock is held.
383378
"""
384-
# noinspection PyBroadException
385379
try:
386380
msg = self.format(record)
387381
try:
@@ -440,7 +434,6 @@ def _do_lock(self):
440434
self._open_lockfile()
441435
if self.stream_lock:
442436
for _i in range(self.maxLockAttempts):
443-
# noinspection PyBroadException
444437
try:
445438
lock(self.stream_lock, LOCK_EX)
446439
self.is_locked = True
@@ -554,7 +547,6 @@ def do_rename(source_fn, dest_fn):
554547
self.num_rollovers += 1
555548
self._console_log("Rotation completed (on size)")
556549

557-
# noinspection PyUnusedLocal
558550
def shouldRollover(self, record):
559551
"""
560552
Determine if rollover should occur.
@@ -605,7 +597,6 @@ def _do_chown_and_chmod(self, filename):
605597
os.chmod(filename, self.chmod)
606598

607599

608-
# noinspection PyProtectedMember
609600
class ConcurrentTimedRotatingFileHandler(TimedRotatingFileHandler):
610601
"""A time-based rotating log handler that supports concurrent access across
611602
multiple processes or hosts (using logs on a shared network drive).
@@ -698,7 +689,6 @@ def emit(self, record):
698689
This also does the formatting *before* locks are obtained, in case the format itself does
699690
logging calls from within. Rollover also occurs while the lock is held.
700691
"""
701-
# noinspection PyBroadException
702692
try:
703693
msg = self.format(record)
704694
try:
@@ -834,7 +824,7 @@ def doRollover(self): # noqa: C901, PLR0912
834824
counter = 0
835825
while os.path.exists(dfn + gzip_ext):
836826
counter += 1
837-
ending = f".{counter-1}{gzip_ext}"
827+
ending = f".{counter - 1}{gzip_ext}"
838828
if dfn.endswith(ending):
839829
dfn = dfn[: -len(ending)]
840830
dfn = f"{dfn}.{counter}"

src/concurrent_log_handler/queue.py

-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ def setup_logging_queues():
112112

113113
def stop_queue_listeners(*listeners):
114114
for listener in listeners:
115-
# noinspection PyBroadException
116115
try: # noqa: SIM105
117116
listener.stop()
118117
# if sys.stderr:
@@ -133,7 +132,6 @@ def get_all_logger_names(include_root=False):
133132
134133
Warning: this is sensitive to internal structures in the standard logging module.
135134
"""
136-
# noinspection PyUnresolvedReferences
137135
rv = list(logging.Logger.manager.loggerDict.keys())
138136
if include_root:
139137
rv.insert(0, "")

src/example.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ def my_logging_setup(log_name="example.log", use_async=False):
5454
"""
5555

5656
# Import this to install logging.handlers.ConcurrentRotatingFileHandler
57-
# The noinspection thing is so PyCharm doesn't think we're using this for no reason
58-
# noinspection PyUnresolvedReferences
59-
import concurrent_log_handler # noqa: F401, I001
57+
import concurrent_log_handler # noqa: F401
6058

6159
logging_config = {
6260
"version": 1,

tests/other/stresstest.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ def checkExitCodes(self):
352352
return True
353353

354354

355-
# noinspection PyUnresolvedReferences
356355
def unified_diff(a, b, out=sys.stdout, out2=None):
357356
import difflib
358357

@@ -366,7 +365,7 @@ def unified_diff(a, b, out=sys.stdout, out2=None):
366365
# line = line.encode(ENCODING)
367366
if PY2:
368367
if not isinstance(line, unicode):
369-
line = unicode(line, ENCODING)
368+
line = unicode(line, ENCODING) # noqa: PLW2901
370369
line_out = line.encode(out.encoding, "ignore").decode(out.encoding)
371370
out.write(line_out)
372371
else:
@@ -375,7 +374,7 @@ def unified_diff(a, b, out=sys.stdout, out2=None):
375374
dfile.write(line)
376375

377376

378-
def main_runner(args):
377+
def main_runner(args): # noqa: PLR0915
379378
parser.add_option(
380379
"--processes",
381380
metavar="NUM",

tests/stresstest.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,11 @@ def emit(self, record):
106106
# Introduce a random chance (e.g., 5%) to skip or duplicate a log message
107107
random_choice = random.randint(1, 100)
108108

109-
if 1 <= random_choice <= 5: # 5% chance to skip a log message # noqa: PLR2004
109+
# 5% chance to skip a log message
110+
if 1 <= random_choice <= 5: # noqa: PLR2004
110111
return
111-
if 6 <= random_choice <= 10: # 5% chance to duplicate a log message # noqa: PLR2004
112+
# 5% chance to duplicate a log message
113+
if 6 <= random_choice <= 10: # noqa: PLR2004
112114
super().emit(record)
113115
super().emit(record)
114116
else:

tests/test_stresstest.py

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
),
104104
),
105105
# TODO: it would be good to have some test cases that verify that backupCount is not exceeded.
106-
107106
# Testing time intervals other than seconds is difficult because the tests would
108107
# take hours unless we find a way to mock things.
109108
}

0 commit comments

Comments
 (0)