From 676d62f0a59d20d965ff4d4b4ed744576c2b3fe5 Mon Sep 17 00:00:00 2001 From: Kenny Huynh Date: Sat, 2 Oct 2021 07:30:29 -0700 Subject: [PATCH] Changed logger name from "filelock._api" to "filelock" (#97) --- README.md | 7 +++++++ src/filelock/_api.py | 3 ++- tests/test_filelock.py | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c071c2..10976df 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,13 @@ with lock: # And released here. ``` +All log messages by this library are made using the *DEBUG* level, under the +`filelock` name. On how to control displaying/hiding that please consult the +[logging documentation of the standard library](https://docs.python.org/3/howto/logging.html). + +E.g. to hide these messages you can use +`logging.getLogger("filelock").setLevel(logging.INFO)`. + ## FileLock vs SoftFileLock diff --git a/src/filelock/_api.py b/src/filelock/_api.py index 9e221b3..b635d84 100644 --- a/src/filelock/_api.py +++ b/src/filelock/_api.py @@ -4,7 +4,8 @@ from ._error import Timeout -_LOGGER = logging.getLogger(__name__) +_LOGGER = logging.getLogger("filelock") +_LOGGER.setLevel(logging.DEBUG) # This is a helper class which is returned by :meth:`BaseFileLock.acquire` and wraps the lock to make sure __enter__ diff --git a/tests/test_filelock.py b/tests/test_filelock.py index d03e6f2..9fcde84 100644 --- a/tests/test_filelock.py +++ b/tests/test_filelock.py @@ -30,6 +30,7 @@ def test_simple(lock_type, tmp_path, caplog): "Lock {} released on {}".format(id(lock), lock_path), ] assert [r.levelno for r in caplog.records] == [logging.DEBUG, logging.DEBUG, logging.DEBUG, logging.DEBUG] + assert [r.name for r in caplog.records] == ["filelock", "filelock", "filelock", "filelock"] @contextmanager