Skip to content

Move lock acquire/release log from INFO to DEBUG #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/filelock/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def acquire(self, timeout=None, poll_intervall=0.05):
self._acquire()

if self.is_locked:
_LOGGER.info("Lock %s acquired on %s", lock_id, lock_filename)
_LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename)
break
elif 0 <= timeout < time.time() - start_time:
_LOGGER.debug("Timeout on acquiring lock %s on %s", lock_id, lock_filename)
Expand Down Expand Up @@ -175,7 +175,7 @@ def release(self, force=False):
_LOGGER.debug("Attempting to release lock %s on %s", lock_id, lock_filename)
self._release()
self._lock_counter = 0
_LOGGER.info("Lock %s released on %s", lock_id, lock_filename)
_LOGGER.debug("Lock %s released on %s", lock_id, lock_filename)

def __enter__(self):
self.acquire()
Expand Down
12 changes: 11 additions & 1 deletion tests/test_filelock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

import logging
import sys
import threading

Expand All @@ -9,7 +10,8 @@


@pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock])
def test_simple(lock_type, tmp_path):
def test_simple(lock_type, tmp_path, caplog):
caplog.set_level(logging.DEBUG)
lock_path = tmp_path / "a"
lock = lock_type(str(lock_path))

Expand All @@ -18,6 +20,14 @@ def test_simple(lock_type, tmp_path):
assert lock is locked
assert not lock.is_locked

assert caplog.messages == [
"Attempting to acquire lock {} on {}".format(id(lock), lock_path),
"Lock {} acquired on {}".format(id(lock), lock_path),
"Attempting to release lock {} on {}".format(id(lock), lock_path),
"Lock {} released on {}".format(id(lock), lock_path),
]
assert [r.levelno for r in caplog.records] == [logging.DEBUG, logging.DEBUG, logging.DEBUG, logging.DEBUG]


@pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock])
def test_nested_context_manager(lock_type, tmp_path):
Expand Down
2 changes: 2 additions & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
autoclass
autodoc
autosectionlabel
caplog
creat
exc
fcntl
filelock
fmt
intersphinx
intervall
levelno
lk
lockfile
msvcrt
Expand Down