From 1b9333964f3e25c510e17b94d887735432587996 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:16:20 +0200 Subject: [PATCH 01/28] driver/common: add logger to Driver base class Set the logger name to "()[drivername]". This should give us consistent logger naming. Signed-off-by: Bastian Krause --- labgrid/driver/common.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/labgrid/driver/common.py b/labgrid/driver/common.py index 4386cad9d..2adf3f893 100644 --- a/labgrid/driver/common.py +++ b/labgrid/driver/common.py @@ -1,3 +1,4 @@ +import logging import subprocess import attr @@ -25,6 +26,11 @@ def __attrs_post_init__(self): if self.target is None: raise BindingError("Drivers can only be created on a valid target") + logger_name = f"{self.__class__.__name__}({self.target.name})" + if self.name: + logger_name += f":{self.name}" + self.logger = logging.getLogger(logger_name) + def get_priority(self, protocol): """Retrieve the priority for a given protocol From a387ffefe41c1f42c5dcd54c0345b3648235dfaf Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:15:38 +0200 Subject: [PATCH 02/28] driver/bareboxdriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/bareboxdriver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/bareboxdriver.py b/labgrid/driver/bareboxdriver.py index 910f25300..0aeb19d67 100644 --- a/labgrid/driver/bareboxdriver.py +++ b/labgrid/driver/bareboxdriver.py @@ -1,4 +1,3 @@ -import logging import shlex import attr @@ -40,7 +39,6 @@ class BareboxDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}:{self.target}") self._status = 0 # barebox' default log level, used as fallback if no log level can be saved self.saved_log_level = 7 From 0f4136fc6aec26809e1a277e1fdeae1454e33338 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:16:34 +0200 Subject: [PATCH 03/28] driver/dediprogflashdriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/dediprogflashdriver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/dediprogflashdriver.py b/labgrid/driver/dediprogflashdriver.py index b2f091885..eb2de7d7c 100644 --- a/labgrid/driver/dediprogflashdriver.py +++ b/labgrid/driver/dediprogflashdriver.py @@ -1,5 +1,4 @@ import os.path -import logging import attr from ..resource import NetworkDediprogFlasher @@ -24,7 +23,6 @@ class DediprogFlashDriver(Driver): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f'{self}') if self.target.env: self.tool = self.target.env.config.get_tool('dpcmd') else: From aab15363b3eb4c4355e863c1779bdbfdc00c2bfd Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:16:49 +0200 Subject: [PATCH 04/28] driver/dockerdriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/dockerdriver.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/labgrid/driver/dockerdriver.py b/labgrid/driver/dockerdriver.py index b88f9df97..49e45f021 100644 --- a/labgrid/driver/dockerdriver.py +++ b/labgrid/driver/dockerdriver.py @@ -1,9 +1,6 @@ """ Class for connecting to a docker daemon running on the host machine. """ - -import logging - import attr from labgrid.factory import target_factory @@ -62,7 +59,6 @@ class DockerDriver(PowerProtocol, Driver): attr.validators.instance_of(list))) def __attrs_post_init__(self): - self.logger = logging.getLogger(f"{self}({self.target})") super().__attrs_post_init__() self._client = None self._container = None From 6a21f770b0ae967c9f48ac1bf0b0283cc912d71d Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:17:01 +0200 Subject: [PATCH 05/28] driver/externalconsoledriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/externalconsoledriver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/externalconsoledriver.py b/labgrid/driver/externalconsoledriver.py index 6ba18b669..2ab16ada5 100644 --- a/labgrid/driver/externalconsoledriver.py +++ b/labgrid/driver/externalconsoledriver.py @@ -1,5 +1,4 @@ import fcntl -import logging import os import select import shlex @@ -25,7 +24,6 @@ class ExternalConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}({self.target})") self.status = 0 self._child = None From 8ba83450d9cbbf175bd89bb56847d34af6dbd70e Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:17:13 +0200 Subject: [PATCH 06/28] driver/fake: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/fake.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/fake.py b/labgrid/driver/fake.py index cf1a6598d..45eb1cb61 100644 --- a/labgrid/driver/fake.py +++ b/labgrid/driver/fake.py @@ -1,5 +1,4 @@ # pylint: disable=arguments-differ -import logging import re import attr @@ -18,7 +17,6 @@ class FakeConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}({self.target})") self.rxq = [] self.txq = [] From e422edaa5913908757f65b17b8cea2dfa4619e73 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:17:35 +0200 Subject: [PATCH 07/28] driver/flashromdriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/flashromdriver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/flashromdriver.py b/labgrid/driver/flashromdriver.py index 1f4c9dbab..452b74686 100644 --- a/labgrid/driver/flashromdriver.py +++ b/labgrid/driver/flashromdriver.py @@ -1,5 +1,4 @@ import os.path -import logging import attr from ..resource import NetworkFlashrom @@ -24,7 +23,6 @@ class FlashromDriver(Driver, BootstrapProtocol): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f'{self}') if self.target.env: self.tool = self.target.env.config.get_tool('flashrom') else: From 36a19d842dff3abae843b7baa955a1c01ff2f5eb Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:17:49 +0200 Subject: [PATCH 08/28] driver/flashscriptdriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/flashscriptdriver.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/labgrid/driver/flashscriptdriver.py b/labgrid/driver/flashscriptdriver.py index f2f8f4834..bf2941d86 100644 --- a/labgrid/driver/flashscriptdriver.py +++ b/labgrid/driver/flashscriptdriver.py @@ -1,4 +1,3 @@ -import logging import attr from ..factory import target_factory @@ -27,10 +26,6 @@ class FlashScriptDriver(Driver): validator=attr.validators.optional(attr.validators.instance_of(list)), ) - def __attrs_post_init__(self): - super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}:{self.target}") - def on_activate(self): pass From 15195fc96a6fe500293e41030b2d76bd77492353 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:18:07 +0200 Subject: [PATCH 09/28] driver/openocddriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/openocddriver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/openocddriver.py b/labgrid/driver/openocddriver.py index 566667764..4ce4cf3ca 100644 --- a/labgrid/driver/openocddriver.py +++ b/labgrid/driver/openocddriver.py @@ -1,4 +1,3 @@ -import logging from itertools import chain import attr @@ -47,7 +46,6 @@ class OpenOCDDriver(Driver, BootstrapProtocol): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}:{self.target}") # FIXME make sure we always have an environment or config if self.target.env: From 42aa9c2ac0e6fa4f5f9edd344ac239e53664929d Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:18:19 +0200 Subject: [PATCH 10/28] driver/qemudriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/qemudriver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/qemudriver.py b/labgrid/driver/qemudriver.py index 6d7daf02b..ecb47c200 100644 --- a/labgrid/driver/qemudriver.py +++ b/labgrid/driver/qemudriver.py @@ -1,6 +1,5 @@ """The QEMUDriver implements a driver to use a QEMU target""" import atexit -import logging import select import shlex import shutil @@ -89,7 +88,6 @@ class QEMUDriver(ConsoleExpectMixin, Driver, PowerProtocol, ConsoleProtocol): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}:") self.status = 0 self.txdelay = None self._child = None From 4667eed07fff7e9236fc670a12461c5442017609 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:18:33 +0200 Subject: [PATCH 11/28] driver/quartushpsdriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/quartushpsdriver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/quartushpsdriver.py b/labgrid/driver/quartushpsdriver.py index 2c15793eb..d8cc0ab2e 100644 --- a/labgrid/driver/quartushpsdriver.py +++ b/labgrid/driver/quartushpsdriver.py @@ -1,7 +1,6 @@ import subprocess import re import time -import logging import attr @@ -28,7 +27,6 @@ class QuartusHPSDriver(Driver): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}({self.target})") # FIXME make sure we always have an environment or config if self.target.env: From c776c6122cc24aa670e52698015bfc250c8a953d Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:18:44 +0200 Subject: [PATCH 12/28] driver/serialdriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/serialdriver.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/labgrid/driver/serialdriver.py b/labgrid/driver/serialdriver.py index 1c172c8f3..884522622 100644 --- a/labgrid/driver/serialdriver.py +++ b/labgrid/driver/serialdriver.py @@ -1,5 +1,3 @@ -import logging - import attr from pexpect import TIMEOUT import serial @@ -26,7 +24,6 @@ class SerialDriver(ConsoleExpectMixin, Driver, ConsoleProtocol): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}({self.target})") if isinstance(self.port, SerialPort): self.serial = serial.Serial() else: From f2aba57c2d3ffa8fb05e1d4681bf61ff49d2295f Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:18:56 +0200 Subject: [PATCH 13/28] driver/shelldriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/shelldriver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/shelldriver.py b/labgrid/driver/shelldriver.py index 6689e2568..682d7189b 100644 --- a/labgrid/driver/shelldriver.py +++ b/labgrid/driver/shelldriver.py @@ -2,7 +2,6 @@ """The ShellDriver provides the CommandProtocol, ConsoleProtocol and InfoProtocol on top of a SerialPort.""" import io -import logging import re import shlex import ipaddress @@ -58,7 +57,6 @@ class ShellDriver(CommandMixin, Driver, CommandProtocol, FileTransferProtocol): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}:{self.target}") self._status = 0 self._xmodem_cached_rx_cmd = "" From 1b99825bf206a917dc03721e71af723f8fc122fd Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:19:29 +0200 Subject: [PATCH 14/28] driver/sigrokdriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/sigrokdriver.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/labgrid/driver/sigrokdriver.py b/labgrid/driver/sigrokdriver.py index 9ee762531..a9bc61f1c 100644 --- a/labgrid/driver/sigrokdriver.py +++ b/labgrid/driver/sigrokdriver.py @@ -1,4 +1,3 @@ -import logging import os.path import re import subprocess @@ -37,7 +36,6 @@ def __attrs_post_init__(self): ) or 'sigrok-cli' else: self.tool = 'sigrok-cli' - self.log = logging.getLogger("SigrokDriver") self._running = False def _create_tmpdir(self): @@ -46,26 +44,26 @@ def _create_tmpdir(self): command = self.sigrok.command_prefix + [ 'mkdir', '-p', self._tmpdir ] - self.log.debug("Tmpdir command: %s", command) + self.logger.debug("Tmpdir command: %s", command) subprocess.call( command, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL ) - self.log.debug("Created tmpdir: %s", self._tmpdir) + self.logger.debug("Created tmpdir: %s", self._tmpdir) self._local_tmpdir = tempfile.mkdtemp(prefix="labgrid-sigrok-") - self.log.debug("Created local tmpdir: %s", self._local_tmpdir) + self.logger.debug("Created local tmpdir: %s", self._local_tmpdir) else: self._tmpdir = tempfile.mkdtemp(prefix="labgrid-sigrok-") - self.log.debug("created tmpdir: %s", self._tmpdir) + self.logger.debug("created tmpdir: %s", self._tmpdir) def _delete_tmpdir(self): if isinstance(self.sigrok, NetworkSigrokUSBDevice): command = self.sigrok.command_prefix + [ 'rm', '-r', self._tmpdir ] - self.log.debug("Tmpdir command: %s", command) + self.logger.debug("Tmpdir command: %s", command) subprocess.call( command, stdin=subprocess.DEVNULL, @@ -98,7 +96,7 @@ def _get_sigrok_prefix(self): @step(title='call', args=['args']) def _call_with_driver(self, *args): combined = self._get_sigrok_prefix() + list(args) - self.log.debug("Combined command: %s", " ".join(combined)) + self.logger.debug("Combined command: %s", " ".join(combined)) self._process = subprocess.Popen( combined, stdout=subprocess.PIPE, @@ -113,7 +111,7 @@ def _call(self, *args): if self.sigrok.channels: combined += ["-C", self.sigrok.channels] combined += list(args) - self.log.debug("Combined command: %s", combined) + self.logger.debug("Combined command: %s", combined) self._process = subprocess.Popen( combined, stdout=subprocess.PIPE, @@ -138,7 +136,7 @@ class SigrokDriver(SigrokCommon): def capture(self, filename, samplerate="200k"): self._filename = filename self._basename = os.path.basename(self._filename) - self.log.debug( + self.logger.debug( "Saving to: %s with basename: %s", self._filename, self._basename ) cmd = [ @@ -166,7 +164,7 @@ def stop(self): self._process.send_signal(signal.SIGINT) stdout, stderr = self._process.communicate() self._process.wait() - self.log.debug("stdout:\n %s\n ----- \n stderr:\n %s", stdout, stderr) + self.logger.debug("stdout:\n %s\n ----- \n stderr:\n %s", stdout, stderr) # Convert from .sr to .csv cmd = [ @@ -177,7 +175,7 @@ def stop(self): self._call(*cmd) self._process.wait() stdout, stderr = self._process.communicate() - self.log.debug("stdout:\n %s\n ----- \n stderr:\n %s", stdout, stderr) + self.logger.debug("stdout:\n %s\n ----- \n stderr:\n %s", stdout, stderr) if isinstance(self.sigrok, NetworkSigrokUSBDevice): subprocess.call([ 'scp', f'{self.sigrok.host}:{os.path.join(self._tmpdir, self._basename)}', @@ -411,7 +409,7 @@ def stop(self): time.sleep(0.1) else: # process did not finish in time - self.log.info("sigrok-cli did not finish in time, increase timeout?") + self.logger.info("sigrok-cli did not finish in time, increase timeout?") self._process.kill() res = [] @@ -428,7 +426,7 @@ def stop(self): # all other lines are actual values res.append(float(line)) _, stderr = self._process.communicate() - self.log.debug("stderr: %s", stderr) + self.logger.debug("stderr: %s", stderr) self._running = False return unit, res From 2d5fb2d7e96d11b99c8a7b3242f8b8384e2bda61 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:19:42 +0200 Subject: [PATCH 15/28] driver/sshdriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/sshdriver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/sshdriver.py b/labgrid/driver/sshdriver.py index 68e9c725a..ee07e6a13 100644 --- a/labgrid/driver/sshdriver.py +++ b/labgrid/driver/sshdriver.py @@ -1,6 +1,5 @@ """The SSHDriver uses SSH as a transport to implement CommandProtocol and FileTransferProtocol""" import contextlib -import logging import os import re import stat @@ -39,7 +38,6 @@ class SSHDriver(CommandMixin, Driver, CommandProtocol, FileTransferProtocol): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}({self.target})") self._keepalive = None def on_activate(self): From 0e34328b59d6c2ae1f146138bb94324b6abd80e8 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:19:53 +0200 Subject: [PATCH 16/28] driver/ubootdriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/ubootdriver.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/labgrid/driver/ubootdriver.py b/labgrid/driver/ubootdriver.py index d721f598c..cc1cd0d4b 100644 --- a/labgrid/driver/ubootdriver.py +++ b/labgrid/driver/ubootdriver.py @@ -1,6 +1,4 @@ """The U-Boot Module contains the UBootDriver""" -import logging - import attr from pexpect import TIMEOUT @@ -48,7 +46,6 @@ class UBootDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}:{self.target}") self._status = 0 if self.boot_expression: From 932b9918d54953139d619f5078c550dc1ebc3cff Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:20:05 +0200 Subject: [PATCH 17/28] driver/usbaudiodriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/usbaudiodriver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/usbaudiodriver.py b/labgrid/driver/usbaudiodriver.py index 01b0f926e..997317668 100644 --- a/labgrid/driver/usbaudiodriver.py +++ b/labgrid/driver/usbaudiodriver.py @@ -1,4 +1,3 @@ -import logging import subprocess import attr @@ -28,7 +27,6 @@ class USBAudioInputDriver(Driver): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}") self._prepared = False def _get_pipeline(self): From 57e5e08765d02d72e20eca8a728c5abc64ee22eb Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:20:21 +0200 Subject: [PATCH 18/28] driver/usbstoragedriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/usbstoragedriver.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/labgrid/driver/usbstoragedriver.py b/labgrid/driver/usbstoragedriver.py index 902fd343a..5bc42856a 100644 --- a/labgrid/driver/usbstoragedriver.py +++ b/labgrid/driver/usbstoragedriver.py @@ -1,5 +1,4 @@ import enum -import logging import os import time import subprocess @@ -42,10 +41,6 @@ class USBStorageDriver(Driver): validator=attr.validators.optional(attr.validators.instance_of(str)) ) - def __attrs_post_init__(self): - super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}:{self.target}") - def on_activate(self): pass From e41f684317c56d41b8ef5b9dfe0dbee3986ea3b7 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:20:32 +0200 Subject: [PATCH 19/28] driver/usbvideodriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/usbvideodriver.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/driver/usbvideodriver.py b/labgrid/driver/usbvideodriver.py index b87df4267..67cf6f87f 100644 --- a/labgrid/driver/usbvideodriver.py +++ b/labgrid/driver/usbvideodriver.py @@ -1,4 +1,3 @@ -import logging import subprocess import attr @@ -18,7 +17,6 @@ class USBVideoDriver(Driver, VideoProtocol): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}") self._prepared = False def get_qualities(self): From 7edac8344cb6d58ebb73ef48e66b9deb96c33198 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 13:20:47 +0200 Subject: [PATCH 20/28] driver/xenadriver: use logger from Driver base class Signed-off-by: Bastian Krause --- labgrid/driver/xenadriver.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/labgrid/driver/xenadriver.py b/labgrid/driver/xenadriver.py index c3993f983..e4139da89 100644 --- a/labgrid/driver/xenadriver.py +++ b/labgrid/driver/xenadriver.py @@ -1,4 +1,3 @@ -import logging from importlib import import_module import attr @@ -17,11 +16,10 @@ def __attrs_post_init__(self): super().__attrs_post_init__() self._xena_app = import_module('xenavalkyrie.xena_app') self._tgn_utils = import_module('trafficgenerator.tgn_utils') - self._logger = logging.getLogger(f"{self}") self._xm = None def on_activate(self): - self._xm = self._xena_app.init_xena(self._tgn_utils.ApiType.socket, self._logger, 'labgrid') + self._xm = self._xena_app.init_xena(self._tgn_utils.ApiType.socket, self.logger, 'labgrid') self._xm.session.add_chassis(self.xena_manager.hostname) def on_deactivate(self): From 96bbe6128a9e9ca337219af294f54f2d3dde771d Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 14:23:22 +0200 Subject: [PATCH 21/28] resource/common: add logger to Resource/ResourceManager Set the logger names to "[()][:]". This should give us consistent logger naming. Signed-off-by: Bastian Krause --- labgrid/resource/common.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/labgrid/resource/common.py b/labgrid/resource/common.py index 1314a9e8c..d2b190750 100644 --- a/labgrid/resource/common.py +++ b/labgrid/resource/common.py @@ -1,3 +1,4 @@ +import logging import shlex from typing import Dict, Type, List import attr @@ -26,6 +27,13 @@ def __attrs_post_init__(self): super().__attrs_post_init__() self._parent = None + logger_name = self.__class__.__name__ + if self.target: + logger_name += f"({self.target.name})" + if self.name: + logger_name += f":{self.name}" + self.logger = logging.getLogger(logger_name) + @property def command_prefix(self): return [] @@ -118,6 +126,7 @@ def get(cls) -> 'ResourceManager': def __attrs_post_init__(self): self.resources: List[ManagedResource] = [] + self.logger = logging.getLogger(str(self)) def _add_resource(self, resource: 'ManagedResource'): self.resources.append(resource) From 7600343626ac003fe36a86b9c977aabb22b3ad4d Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 14:24:21 +0200 Subject: [PATCH 22/28] resource/docker: use logger from Resource(Manager) Signed-off-by: Bastian Krause --- labgrid/resource/docker.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/labgrid/resource/docker.py b/labgrid/resource/docker.py index c6f37294a..626e4f803 100644 --- a/labgrid/resource/docker.py +++ b/labgrid/resource/docker.py @@ -4,7 +4,6 @@ in the specification (e.g. yaml) of DockerDriver. """ -import logging import socket import attr @@ -34,7 +33,6 @@ class DockerManager(ResourceManager): def __attrs_post_init__(self): super().__attrs_post_init__() - self.log = logging.getLogger('DockerManager') self._client = dict() self._docker_daemons_cleaned = list() @@ -71,7 +69,7 @@ def _container_cleanup(self, docker_client): for container in container_list: if (container['Labels'][DockerConstants.DOCKER_LG_CLEANUP_LABEL] == DockerConstants.DOCKER_LG_CLEANUP_TYPE_AUTO): - self.log.info("Deleting container %s", container['Names'][0]) + self.logger.info("Deleting container %s", container['Names'][0]) docker_client.api.remove_container(container['Id'], force=True) self._docker_daemons_cleaned.append(docker_client.api.base_url) @@ -90,7 +88,6 @@ class DockerDaemon(ManagedResource): def __attrs_post_init__(self): super().__attrs_post_init__() self._nw_services = dict() - self.log = logging.getLogger('DockerContainer') self.timeout = 5.0 self.avail = True @@ -132,7 +129,7 @@ class and the resource is identified as available. if nw_service.address == "": container = docker_client.api.containers( filters={"name": "/" + container_name}) - self.log.debug("Containers found %s", container) + self.logger.debug("Containers found %s", container) if container: nw_service.address = find_dict( d=container[0]['NetworkSettings'], From 71c5589c773704f2307f28b10c28b6a7c79ac3f7 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 14:25:27 +0200 Subject: [PATCH 23/28] resource/ethernetport: use logger from ResourceManager Signed-off-by: Bastian Krause --- labgrid/resource/ethernetport.py | 1 - 1 file changed, 1 deletion(-) diff --git a/labgrid/resource/ethernetport.py b/labgrid/resource/ethernetport.py index d66fcd799..0020f26ba 100644 --- a/labgrid/resource/ethernetport.py +++ b/labgrid/resource/ethernetport.py @@ -183,7 +183,6 @@ class EthernetPortManager(ResourceManager): """The EthernetPortManager periodically polls the switch for new updates.""" def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}") self.loop = None self.poll_tasks = [] self.switches = {} From be3cc7e99379d5f69c22cc1727bdc95b4ed0acce Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 14:25:56 +0200 Subject: [PATCH 24/28] resource/lxaiobus: use logger from ResourceManager Signed-off-by: Bastian Krause --- labgrid/resource/lxaiobus.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/labgrid/resource/lxaiobus.py b/labgrid/resource/lxaiobus.py index 4367e5927..1645346eb 100644 --- a/labgrid/resource/lxaiobus.py +++ b/labgrid/resource/lxaiobus.py @@ -1,4 +1,3 @@ -import logging from time import monotonic from importlib import import_module @@ -14,8 +13,6 @@ def __attrs_post_init__(self): super().__attrs_post_init__() self._requests = import_module('requests') - self.log = logging.getLogger('LXAIOBusNodeManager') - self._last = 0.0 def _get_nodes(self, host): @@ -25,7 +22,7 @@ def _get_nodes(self, host): j = r.json() return j["result"] except self._requests.exceptions.ConnectionError: - self.log.exception("failed to connect to host %s", host) + self.logger.exception("failed to connect to host %s", host) return [] def poll(self): From 26dffe45082a3ac46f930fc408d96c7d8416a069 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 14:26:08 +0200 Subject: [PATCH 25/28] resource/mqtt: use logger from ResourceManager Signed-off-by: Bastian Krause --- labgrid/resource/mqtt.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/labgrid/resource/mqtt.py b/labgrid/resource/mqtt.py index 98be9b722..b5991537b 100644 --- a/labgrid/resource/mqtt.py +++ b/labgrid/resource/mqtt.py @@ -1,4 +1,3 @@ -import logging import threading from time import monotonic @@ -16,10 +15,6 @@ class MQTTManager(ResourceManager): _topic_lock = attr.ib(default=threading.Lock()) _last = attr.ib(default=0.0, validator=attr.validators.instance_of(float)) - def __attrs_post_init__(self): - super().__attrs_post_init__() - self.log = logging.getLogger('MQTTManager') - def _create_mqtt_connection(self, host): import paho.mqtt.client as mqtt client = mqtt.Client() From ee2cfbe4f05de14947637277e8fa3e04979eb144 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 14:26:29 +0200 Subject: [PATCH 26/28] resource/remote: use logger from ResourceManager Signed-off-by: Bastian Krause --- labgrid/resource/remote.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/labgrid/resource/remote.py b/labgrid/resource/remote.py index bca849bf0..ad116382d 100644 --- a/labgrid/resource/remote.py +++ b/labgrid/resource/remote.py @@ -1,5 +1,4 @@ import copy -import logging import os import attr @@ -11,7 +10,6 @@ class RemotePlaceManager(ResourceManager): def __attrs_post_init__(self): super().__attrs_post_init__() - self.logger = logging.getLogger(f"{self}") self.url = None self.realm = None self.loop = None From 3d156a12bad994bc1fab6f130e6dbf686e538f45 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 14:26:48 +0200 Subject: [PATCH 27/28] resource/udev: use logger from ResourceManager Signed-off-by: Bastian Krause --- labgrid/resource/udev.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/labgrid/resource/udev.py b/labgrid/resource/udev.py index 819f5cbba..600bb1a62 100644 --- a/labgrid/resource/udev.py +++ b/labgrid/resource/udev.py @@ -1,4 +1,3 @@ -import logging import os import queue import warnings @@ -19,7 +18,6 @@ def __attrs_post_init__(self): super().__attrs_post_init__() self.queue = queue.Queue() - self.log = logging.getLogger('UdevManager') self._pyudev = import_module('pyudev') self._context = self._pyudev.Context() self._monitor = self._pyudev.Monitor.from_netlink(self._context) @@ -32,7 +30,7 @@ def on_resource_added(self, resource): devices.match_subsystem(resource.match['SUBSYSTEM']) for device in devices: if resource.try_match(device): - self.log.debug(" matched successfully against %s", resource.device) + self.logger.debug(" matched successfully against %s", resource.device) def _insert_into_queue(self, device): self.queue.put(device) @@ -44,10 +42,10 @@ def poll(self): device = self.queue.get(False) except queue.Empty: break - self.log.debug("%s: %s", device.action, device) + self.logger.debug("%s: %s", device.action, device) for resource in self.resources: if resource.try_match(device): - self.log.debug(" matched successfully") + self.logger.debug(" matched successfully") @attr.s(eq=False) class USBResource(ManagedResource): @@ -59,7 +57,6 @@ class USBResource(ManagedResource): def __attrs_post_init__(self): self.timeout = 5.0 - self.log = logging.getLogger('USBResource') self.match.setdefault('SUBSYSTEM', 'usb') super().__attrs_post_init__() @@ -134,7 +131,7 @@ def match_ancestors(key, value): if self.device.sys_path != device.sys_path: return False - self.log.debug(" found match: %s", self) + self.logger.debug(" found match: %s", self) if self.suggest and device.action in [None, 'add']: self.device = device From 2a095c28681511c6cda9900aea2ea62d807e9089 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 28 Jul 2023 14:35:12 +0200 Subject: [PATCH 28/28] util/qmp: drop colon from logger name Logger names should not contain any formatting. Signed-off-by: Bastian Krause --- labgrid/util/qmp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labgrid/util/qmp.py b/labgrid/util/qmp.py index 8af3b7c01..1eabce2c4 100644 --- a/labgrid/util/qmp.py +++ b/labgrid/util/qmp.py @@ -9,7 +9,7 @@ class QMPMonitor: monitor_in = attr.ib() def __attrs_post_init__(self): - self.logger = logging.getLogger(f"{self}:") + self.logger = logging.getLogger(f"{self}") self._negotiate_capabilities() def _negotiate_capabilities(self):