Skip to content

Commit

Permalink
Move lock acquire/release log from INFO to DEBUG (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Sep 28, 2021
1 parent 30ef634 commit 684d69d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit 684d69d

Please sign in to comment.