qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: "Alex Bennée" <alex.bennee@linaro.org>,
	qemu-devel@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: "Ani Sinha" <anisinha@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P . Berrange" <berrange@redhat.com>,
	"John Snow" <jsnow@redhat.com>, "Cédric Le Goater" <clg@kaod.org>,
	"Fabiano Rosas" <farosas@suse.de>
Subject: [PATCH 09/11] tests/functional: Set up logging
Date: Tue, 16 Jul 2024 13:26:12 +0200	[thread overview]
Message-ID: <20240716112614.1755692-10-thuth@redhat.com> (raw)
In-Reply-To: <20240716112614.1755692-1-thuth@redhat.com>

Create log files for each test separately, one file that contains
the basic logging and one that contains the console output.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/functional/qemu_test/__init__.py | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/tests/functional/qemu_test/__init__.py b/tests/functional/qemu_test/__init__.py
index 77c3b14d34..cc49fd4c94 100644
--- a/tests/functional/qemu_test/__init__.py
+++ b/tests/functional/qemu_test/__init__.py
@@ -208,7 +208,7 @@ class QemuBaseTest(unittest.TestCase):
     BUILD_DIR = _build_dir()
 
     workdir = None
-    log = logging.getLogger('qemu-test')
+    log = None
 
     def setUp(self, bin_prefix):
         self.assertIsNotNone(self.qemu_bin, 'QEMU_TEST_QEMU_BINARY must be set')
@@ -218,6 +218,18 @@ def setUp(self, bin_prefix):
         if not os.path.exists(self.workdir):
             os.makedirs(self.workdir)
 
+        self.log = logging.getLogger('qemu-test')
+        self.log.setLevel(logging.DEBUG)
+        self._log_fh = logging.FileHandler(os.path.join(self.workdir,
+                                                        'base.log'), mode='w')
+        self._log_fh.setLevel(logging.DEBUG)
+        fileFormatter = logging.Formatter('%(asctime)s - %(levelname)s: %(message)s')
+        self._log_fh.setFormatter(fileFormatter)
+        self.log.addHandler(self._log_fh)
+
+    def tearDown(self):
+        self.log.removeHandler(self._log_fh)
+
     def check_hash(self, file_name, expected_hash):
         if not expected_hash:
             return True
@@ -269,6 +281,15 @@ def setUp(self):
 
         super().setUp('qemu-system-')
 
+        console_log = logging.getLogger('console')
+        console_log.setLevel(logging.DEBUG)
+        self._console_log_fh = logging.FileHandler(os.path.join(self.workdir,
+                                                   'console.log'), mode='w')
+        self._console_log_fh.setLevel(logging.DEBUG)
+        fileFormatter = logging.Formatter('%(asctime)s: %(message)s')
+        self._console_log_fh.setFormatter(fileFormatter)
+        console_log.addHandler(self._console_log_fh)
+
     def set_machine(self, machinename):
         # TODO: We should use QMP to get the list of available machines
         if not self._machinehelp:
@@ -359,4 +380,5 @@ def set_vm_arg(self, arg, value):
     def tearDown(self):
         for vm in self._vms.values():
             vm.shutdown()
+        logging.getLogger('console').removeHandler(self._console_log_fh)
         super().tearDown()
-- 
2.45.2



  parent reply	other threads:[~2024-07-16 11:28 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16 11:26 [PATCH v1 00/11] Convert avocado tests to normal Python unittests Thomas Huth
2024-07-16 11:26 ` [PATCH 01/11] tests/functional: Add base classes for the upcoming pytest-based tests Thomas Huth
2024-07-16 11:26 ` [PATCH 02/11] tests/functional: Convert simple avocado tests into standalone python tests Thomas Huth
2024-07-16 18:14   ` Daniel P. Berrangé
2024-07-16 11:26 ` [PATCH 03/11] tests/functional: Convert avocado tests that just need a small adjustment Thomas Huth
2024-07-16 18:15   ` Daniel P. Berrangé
2024-07-16 11:26 ` [PATCH 04/11] tests/functional: Add python-based tests to the meson build system Thomas Huth
2024-07-16 15:15   ` Fabiano Rosas
2024-07-17  9:20     ` Thomas Huth
2024-07-16 16:55   ` Daniel P. Berrangé
2024-07-16 11:26 ` [PATCH 05/11] tests/functional: Implement fetch_asset() method for downloading assets Thomas Huth
2024-07-16 18:17   ` Daniel P. Berrangé
2024-07-16 11:26 ` [PATCH 06/11] tests/functional: Convert some tests that download files via fetch_asset() Thomas Huth
2024-07-16 18:19   ` Daniel P. Berrangé
2024-07-16 11:26 ` [PATCH 07/11] tests/functional: Add a function for extracting files from an archive Thomas Huth
2024-07-16 18:20   ` Daniel P. Berrangé
2024-07-16 11:26 ` [PATCH 08/11] tests/functional: Convert some avocado tests that needed avocado.utils.archive Thomas Huth
2024-07-16 18:20   ` Daniel P. Berrangé
2024-07-16 11:26 ` Thomas Huth [this message]
2024-07-16 18:22   ` [PATCH 09/11] tests/functional: Set up logging Daniel P. Berrangé
2024-07-16 11:26 ` [PATCH 10/11] tests/functional: Convert the s390x avocado tests into standalone tests Thomas Huth
2024-07-16 18:24   ` Daniel P. Berrangé
2024-07-16 11:26 ` [PATCH 11/11] gitlab-ci: Add "check-functional" to the build tests Thomas Huth
2024-07-16 18:25   ` Daniel P. Berrangé
2024-07-16 16:51 ` [PATCH v1 00/11] Convert avocado tests to normal Python unittests Daniel P. Berrangé
2024-07-16 17:03   ` Thomas Huth
2024-07-17  8:04     ` Thomas Huth
2024-07-17  8:37       ` Daniel P. Berrangé
2024-07-17  8:53         ` Thomas Huth
2024-07-16 17:57 ` Paolo Bonzini
2024-07-24 11:43   ` Thomas Huth
2024-07-25 14:21 ` Cleber Rosa
2024-07-26 10:07   ` Thomas Huth
2024-07-26 13:56     ` Cleber Rosa
2024-07-29 12:44   ` Daniel P. Berrangé
2024-07-29 14:01     ` Cleber Rosa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240716112614.1755692-10-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=anisinha@redhat.com \
    --cc=berrange@redhat.com \
    --cc=clg@kaod.org \
    --cc=farosas@suse.de \
    --cc=jsnow@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).