[PATCH 1/2] tests/functional: include logger name and function in messages

Daniel P. Berrangé posted 2 patches 2 weeks, 2 days ago
Maintainers: Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>
[PATCH 1/2] tests/functional: include logger name and function in messages
Posted by Daniel P. Berrangé 2 weeks, 2 days ago
As we collect debug logs from a wide range of code it becomes
increasingly confusing to understand where each log messages comes
from. Adding "%(name)s" gives us the logger name, which is usually
based on the python __name__ symbol, aka the code module name.
Then "%(funcName)s" completes the story by identifying the function.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/functional/qemu_test/testcase.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index 2c0abde395..6fc6e1ac0a 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -217,7 +217,7 @@ def setUp(self):
         self._log_fh = logging.FileHandler(self.log_filename, mode='w')
         self._log_fh.setLevel(logging.DEBUG)
         fileFormatter = logging.Formatter(
-            '%(asctime)s - %(levelname)s: %(message)s')
+            '%(asctime)s - %(levelname)s: %(name)s.%(funcName)s %(message)s')
         self._log_fh.setFormatter(fileFormatter)
         self.log.addHandler(self._log_fh)
 
-- 
2.51.1


Re: [PATCH 1/2] tests/functional: include logger name and function in messages
Posted by Thomas Huth 2 weeks, 2 days ago
On 28/10/2025 19.26, Daniel P. Berrangé wrote:
> As we collect debug logs from a wide range of code it becomes
> increasingly confusing to understand where each log messages comes
> from. Adding "%(name)s" gives us the logger name, which is usually
> based on the python __name__ symbol, aka the code module name.
> Then "%(funcName)s" completes the story by identifying the function.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   tests/functional/qemu_test/testcase.py | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
> index 2c0abde395..6fc6e1ac0a 100644
> --- a/tests/functional/qemu_test/testcase.py
> +++ b/tests/functional/qemu_test/testcase.py
> @@ -217,7 +217,7 @@ def setUp(self):
>           self._log_fh = logging.FileHandler(self.log_filename, mode='w')
>           self._log_fh.setLevel(logging.DEBUG)
>           fileFormatter = logging.Formatter(
> -            '%(asctime)s - %(levelname)s: %(message)s')
> +            '%(asctime)s - %(levelname)s: %(name)s.%(funcName)s %(message)s')
>           self._log_fh.setFormatter(fileFormatter)
>           self.log.addHandler(self._log_fh)
>   

Reviewed-by: Thomas Huth <thuth@redhat.com>