fix: multiple calls on the root logger instead of module logger (#421)
This commit is contained in:
parent
45acd54868
commit
b7c4a3117e
@ -171,6 +171,7 @@ select = [
|
|||||||
"W", # pycodestyle
|
"W", # pycodestyle
|
||||||
"UP", # pyupgrade
|
"UP", # pyupgrade
|
||||||
"I", # isort
|
"I", # isort
|
||||||
|
"LOG", # log
|
||||||
"RUF", # ruff specific
|
"RUF", # ruff specific
|
||||||
"FLY", # flynt
|
"FLY", # flynt
|
||||||
"FURB", # refurb
|
"FURB", # refurb
|
||||||
|
|||||||
@ -29,6 +29,8 @@ from .proxy_object import ProxyObject
|
|||||||
|
|
||||||
NO_REPLY_EXPECTED_VALUE = MessageFlag.NO_REPLY_EXPECTED.value
|
NO_REPLY_EXPECTED_VALUE = MessageFlag.NO_REPLY_EXPECTED.value
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _generate_hello_serialized(next_serial: int) -> bytes:
|
def _generate_hello_serialized(next_serial: int) -> bytes:
|
||||||
return bytes(
|
return bytes(
|
||||||
@ -442,7 +444,7 @@ class MessageBus(BaseMessageBus):
|
|||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception("unexpected exception in future", exc_info=e)
|
_LOGGER.exception("unexpected exception in future", exc_info=e)
|
||||||
|
|
||||||
def _make_method_handler(
|
def _make_method_handler(
|
||||||
self, interface: ServiceInterface, method: _Method
|
self, interface: ServiceInterface, method: _Method
|
||||||
@ -534,17 +536,17 @@ class MessageBus(BaseMessageBus):
|
|||||||
try:
|
try:
|
||||||
self._sock.close()
|
self._sock.close()
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.warning("could not close socket", exc_info=True)
|
_LOGGER.warning("could not close socket", exc_info=True)
|
||||||
|
|
||||||
def _finalize(self, err: Exception | None = None) -> None:
|
def _finalize(self, err: Exception | None = None) -> None:
|
||||||
try:
|
try:
|
||||||
self._loop.remove_reader(self._fd)
|
self._loop.remove_reader(self._fd)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.warning("could not remove message reader", exc_info=True)
|
_LOGGER.warning("could not remove message reader", exc_info=True)
|
||||||
try:
|
try:
|
||||||
self._loop.remove_writer(self._fd)
|
self._loop.remove_writer(self._fd)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.warning("could not remove message writer", exc_info=True)
|
_LOGGER.warning("could not remove message writer", exc_info=True)
|
||||||
|
|
||||||
had_handlers = bool(self._method_return_handlers or self._user_message_handlers)
|
had_handlers = bool(self._method_return_handlers or self._user_message_handlers)
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,8 @@ from typing import Callable
|
|||||||
from .._private.unmarshaller import Unmarshaller
|
from .._private.unmarshaller import Unmarshaller
|
||||||
from ..message import Message
|
from ..message import Message
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _message_reader(
|
def _message_reader(
|
||||||
unmarshaller: Unmarshaller,
|
unmarshaller: Unmarshaller,
|
||||||
@ -24,7 +26,7 @@ def _message_reader(
|
|||||||
try:
|
try:
|
||||||
process(message)
|
process(message)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.error("Unexpected error processing message: %s", exc_info=True)
|
_LOGGER.error("Unexpected error processing message: %s", exc_info=True)
|
||||||
# If we are not negotiating unix fds, we can stop reading as soon as we have
|
# If we are not negotiating unix fds, we can stop reading as soon as we have
|
||||||
# the buffer is empty as asyncio will call us again when there is more data.
|
# the buffer is empty as asyncio will call us again when there is more data.
|
||||||
if (
|
if (
|
||||||
|
|||||||
@ -19,6 +19,9 @@ from ..message import Message
|
|||||||
from ..message_bus import BaseMessageBus
|
from ..message_bus import BaseMessageBus
|
||||||
from .proxy_object import ProxyObject
|
from .proxy_object import ProxyObject
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# glib is optional
|
# glib is optional
|
||||||
_import_error = None
|
_import_error = None
|
||||||
try:
|
try:
|
||||||
@ -179,7 +182,7 @@ class MessageBus(BaseMessageBus):
|
|||||||
try:
|
try:
|
||||||
self._process_message(msg)
|
self._process_message(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(
|
_LOGGER.exception(
|
||||||
f"got unexpected error processing a message: {e}.\n{traceback.format_exc()}"
|
f"got unexpected error processing a message: {e}.\n{traceback.format_exc()}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -334,7 +334,7 @@ class BaseMessageBus:
|
|||||||
try:
|
try:
|
||||||
raise e
|
raise e
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.error(
|
_LOGGER.error(
|
||||||
"An exception ocurred when emitting ObjectManager.InterfacesAdded for %s. "
|
"An exception ocurred when emitting ObjectManager.InterfacesAdded for %s. "
|
||||||
"Some properties will not be included in the signal.",
|
"Some properties will not be included in the signal.",
|
||||||
interface.name,
|
interface.name,
|
||||||
@ -526,7 +526,7 @@ class BaseMessageBus:
|
|||||||
try:
|
try:
|
||||||
self._sock.shutdown(socket.SHUT_RDWR)
|
self._sock.shutdown(socket.SHUT_RDWR)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.warning("could not shut down socket", exc_info=True)
|
_LOGGER.warning("could not shut down socket", exc_info=True)
|
||||||
|
|
||||||
def next_serial(self) -> int:
|
def next_serial(self) -> int:
|
||||||
"""Get the next serial for this bus. This can be used as the ``serial``
|
"""Get the next serial for this bus. This can be used as the ``serial``
|
||||||
@ -601,7 +601,7 @@ class BaseMessageBus:
|
|||||||
try:
|
try:
|
||||||
handler(None, err)
|
handler(None, err)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.warning(
|
_LOGGER.warning(
|
||||||
"a message handler threw an exception on shutdown", exc_info=True
|
"a message handler threw an exception on shutdown", exc_info=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -804,9 +804,9 @@ class BaseMessageBus:
|
|||||||
self.send(e._as_message(msg))
|
self.send(e._as_message(msg))
|
||||||
handled = True
|
handled = True
|
||||||
break
|
break
|
||||||
logging.exception("A message handler raised an exception: %s", e)
|
_LOGGER.exception("A message handler raised an exception: %s", e)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception("A message handler raised an exception: %s", e)
|
_LOGGER.exception("A message handler raised an exception: %s", e)
|
||||||
if msg.message_type is MESSAGE_TYPE_CALL:
|
if msg.message_type is MESSAGE_TYPE_CALL:
|
||||||
self.send(
|
self.send(
|
||||||
Message.new_error(
|
Message.new_error(
|
||||||
@ -1219,11 +1219,11 @@ class BaseMessageBus:
|
|||||||
|
|
||||||
def add_match_notify(msg: Message | None, err: Exception | None) -> None:
|
def add_match_notify(msg: Message | None, err: Exception | None) -> None:
|
||||||
if err:
|
if err:
|
||||||
logging.error(
|
_LOGGER.error(
|
||||||
f'add match request failed. match="{self._name_owner_match_rule}", {err}'
|
f'add match request failed. match="{self._name_owner_match_rule}", {err}'
|
||||||
)
|
)
|
||||||
elif msg is not None and msg.message_type == MessageType.ERROR:
|
elif msg is not None and msg.message_type == MessageType.ERROR:
|
||||||
logging.error(
|
_LOGGER.error(
|
||||||
f'add match request failed. match="{self._name_owner_match_rule}", {msg.body[0]}'
|
f'add match request failed. match="{self._name_owner_match_rule}", {msg.body[0]}'
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1254,9 +1254,9 @@ class BaseMessageBus:
|
|||||||
|
|
||||||
def add_match_notify(msg: Message | None, err: Exception | None) -> None:
|
def add_match_notify(msg: Message | None, err: Exception | None) -> None:
|
||||||
if err:
|
if err:
|
||||||
logging.error(f'add match request failed. match="{match_rule}", {err}')
|
_LOGGER.error(f'add match request failed. match="{match_rule}", {err}')
|
||||||
elif msg is not None and msg.message_type == MessageType.ERROR:
|
elif msg is not None and msg.message_type == MessageType.ERROR:
|
||||||
logging.error(
|
_LOGGER.error(
|
||||||
f'add match request failed. match="{match_rule}", {msg.body[0]}'
|
f'add match request failed. match="{match_rule}", {msg.body[0]}'
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1290,11 +1290,11 @@ class BaseMessageBus:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if err:
|
if err:
|
||||||
logging.error(
|
_LOGGER.error(
|
||||||
f'remove match request failed. match="{match_rule}", {err}'
|
f'remove match request failed. match="{match_rule}", {err}'
|
||||||
)
|
)
|
||||||
elif msg is not None and msg.message_type == MessageType.ERROR:
|
elif msg is not None and msg.message_type == MessageType.ERROR:
|
||||||
logging.error(
|
_LOGGER.error(
|
||||||
f'remove match request failed. match="{match_rule}", {msg.body[0]}'
|
f'remove match request failed. match="{match_rule}", {msg.body[0]}'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,8 @@ from .message import Message
|
|||||||
from .unpack import unpack_variants as unpack
|
from .unpack import unpack_variants as unpack
|
||||||
from .validators import assert_bus_name_valid, assert_object_path_valid
|
from .validators import assert_bus_name_valid, assert_object_path_valid
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SignalHandler:
|
class SignalHandler:
|
||||||
@ -123,7 +125,7 @@ class BaseProxyInterface:
|
|||||||
return
|
return
|
||||||
intr_signal = match[0]
|
intr_signal = match[0]
|
||||||
if intr_signal.signature != msg.signature:
|
if intr_signal.signature != msg.signature:
|
||||||
logging.warning(
|
_LOGGER.warning(
|
||||||
f'got signal "{self.introspection.name}.{msg.member}" with unexpected signature "{msg.signature}"'
|
f'got signal "{self.introspection.name}.{msg.member}" with unexpected signature "{msg.signature}"'
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@ -316,11 +318,11 @@ class BaseProxyObject:
|
|||||||
|
|
||||||
def get_owner_notify(msg: Message, err: Exception | None) -> None:
|
def get_owner_notify(msg: Message, err: Exception | None) -> None:
|
||||||
if err:
|
if err:
|
||||||
logging.error(f'getting name owner for "{name}" failed, {err}')
|
_LOGGER.error(f'getting name owner for "{name}" failed, {err}')
|
||||||
return
|
return
|
||||||
if msg.message_type == MessageType.ERROR:
|
if msg.message_type == MessageType.ERROR:
|
||||||
if msg.error_name != ErrorType.NAME_HAS_NO_OWNER.value:
|
if msg.error_name != ErrorType.NAME_HAS_NO_OWNER.value:
|
||||||
logging.error(
|
_LOGGER.error(
|
||||||
f'getting name owner for "{name}" failed, {msg.body[0]}'
|
f'getting name owner for "{name}" failed, {msg.body[0]}'
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user