From 30a06b5f9a707ad442c3e42722598ef66dd1114e Mon Sep 17 00:00:00 2001 From: khuynh Date: Fri, 1 Oct 2021 11:03:40 -0700 Subject: [PATCH 1/6] Changed logger name from "filelock._api" to "filelock" --- src/filelock/_api.py | 2 +- tests/test_filelock.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/filelock/_api.py b/src/filelock/_api.py index 9e221b3..3ecf12e 100644 --- a/src/filelock/_api.py +++ b/src/filelock/_api.py @@ -4,7 +4,7 @@ from ._error import Timeout -_LOGGER = logging.getLogger(__name__) +_LOGGER = logging.getLogger("filelock") # 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..0d8a9d3 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 @@ -333,3 +334,14 @@ def test_cleanup_soft_lock(tmp_path): with lock: assert lock_path.exists() assert not lock_path.exists() + + +def test_logger_name(): + # need to check both that the filelock logger exists and is not created as + # a logging.PlaceHolder as a side-effect of creating a filelock child + # logger + # + # e.g. filelock._api creates a logger.PlaceHolder for "filelock" and a + # logger.Logger for "filelock._api" + assert "filelock" in logging.root.manager.loggerDict + assert isinstance(logging.root.manager.loggerDict["filelock"], logging.Logger) From 35e8ff0ccb399755f0c0d104e0fe683950cf526c Mon Sep 17 00:00:00 2001 From: khuynh Date: Fri, 1 Oct 2021 11:13:25 -0700 Subject: [PATCH 2/6] Added section to README about adjusting the log level --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 5c071c2..3efd479 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,18 @@ with lock: ``` +### Adjusting the Log Level + +By default, the logger name is *"filelock"* and the logging level is set to +*logging.WARNING*. This can be adjusted using the *logging* module. + +```Python +import logging + +logging.getLogger("filelock").setLevel(logging.ERROR) +``` + + ## FileLock vs SoftFileLock The *FileLock* is platform dependent while the *SoftFileLock* is not. Use the From 2674a6a598c6180ad571e456638ebf1ea0dd4360 Mon Sep 17 00:00:00 2001 From: khuynh Date: Fri, 1 Oct 2021 11:27:00 -0700 Subject: [PATCH 3/6] Removed redundant test --- tests/test_filelock.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/test_filelock.py b/tests/test_filelock.py index 0d8a9d3..9fcde84 100644 --- a/tests/test_filelock.py +++ b/tests/test_filelock.py @@ -334,14 +334,3 @@ def test_cleanup_soft_lock(tmp_path): with lock: assert lock_path.exists() assert not lock_path.exists() - - -def test_logger_name(): - # need to check both that the filelock logger exists and is not created as - # a logging.PlaceHolder as a side-effect of creating a filelock child - # logger - # - # e.g. filelock._api creates a logger.PlaceHolder for "filelock" and a - # logger.Logger for "filelock._api" - assert "filelock" in logging.root.manager.loggerDict - assert isinstance(logging.root.manager.loggerDict["filelock"], logging.Logger) From f9cd9e21536bad17e08866e6d185ed720c74e37c Mon Sep 17 00:00:00 2001 From: khuynh Date: Fri, 1 Oct 2021 11:44:14 -0700 Subject: [PATCH 4/6] Set log level to DEBUG --- src/filelock/_api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/filelock/_api.py b/src/filelock/_api.py index 3ecf12e..b635d84 100644 --- a/src/filelock/_api.py +++ b/src/filelock/_api.py @@ -5,6 +5,7 @@ from ._error import Timeout _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__ From 4d8dee0abcac94026f2af08893422eb2df1deb08 Mon Sep 17 00:00:00 2001 From: khuynh Date: Fri, 1 Oct 2021 11:52:00 -0700 Subject: [PATCH 5/6] Update README documentation on logging --- README.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3efd479..5d111b3 100644 --- a/README.md +++ b/README.md @@ -111,17 +111,12 @@ with lock: # And released here. ``` +All log messages by this library are made using the *DEBUG* level. On how to +control displaying/hiding that please consult the +[logging documentation of the standard library](https://docs.python.org/3/howto/logging.html). -### Adjusting the Log Level - -By default, the logger name is *"filelock"* and the logging level is set to -*logging.WARNING*. This can be adjusted using the *logging* module. - -```Python -import logging - -logging.getLogger("filelock").setLevel(logging.ERROR) -``` +E.g. to hide these messages you can use +`logging.getLogger("filelock").setLevel(logging.INFO)`. ## FileLock vs SoftFileLock From 19a53861b14aeb4a5f1886daa00ed3dcf05df6a7 Mon Sep 17 00:00:00 2001 From: khuynh Date: Fri, 1 Oct 2021 11:56:47 -0700 Subject: [PATCH 6/6] Documented the logger name --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d111b3..10976df 100644 --- a/README.md +++ b/README.md @@ -111,8 +111,8 @@ with lock: # And released here. ``` -All log messages by this library are made using the *DEBUG* level. On how to -control displaying/hiding that please consult the +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