Skip to content

Commit

Permalink
Reduce logger path for Subprocess and SSHClient
Browse files Browse the repository at this point in the history
  • Loading branch information
penguinolog committed Nov 29, 2019
1 parent 015d559 commit 89ecb58
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -114,7 +114,7 @@ Creation from scratch:
password='password', # type: typing.Optional[str]
key=None, # type: typing.Optional[paramiko.RSAKey]
keys=None, # type: typing.Optional[typing.Iterable[paramiko.RSAKey]],
key_filename=None, # type: typing.Union[typing.List[str], str, None]
key_filename=None, # type: typing.Union[typing.List[str], None]
passphrase=None, # type: typing.Optional[str]
)
Expand Down
4 changes: 1 addition & 3 deletions doc/source/Subprocess.rst
Expand Up @@ -8,14 +8,12 @@ API: Subprocess
.. py:class:: Subprocess()
.. py:method:: __init__(logger, log_mask_re=None, *, logger=logging.getLogger("exec_helpers.subprocess_runner"))
.. py:method:: __init__(logger, log_mask_re=None)
ExecHelper global API.

:param log_mask_re: regex lookup rule to mask command for logger. all MATCHED groups will be replaced by '<*masked*>'
:type log_mask_re: typing.Optional[str]
:param logger: logger instance to use
:type logger: logging.Logger

.. versionchanged:: 1.2.0 log_mask_re regex rule for masking cmd
.. versionchanged:: 3.1.0 Not singleton anymore. Only lock is shared between all instances.
Expand Down
3 changes: 2 additions & 1 deletion exec_helpers/_ssh_client_base.py
Expand Up @@ -283,8 +283,9 @@ def __init__(
real_auth = self.__auth_mapping[self.hostname]

# Init super with host and real port and username
mod_name = "exec_helpers" if self.__module__.startswith("exec_helpers") else self.__module__
super(SSHClientBase, self).__init__(
logger=logging.getLogger(f"{self.__module__}.{self.__class__.__name__}").getChild(
logger=logging.getLogger(f"{mod_name}.{self.__class__.__name__}").getChild(
f"({real_auth.username}@{host}:{self.__port})"
)
)
Expand Down
14 changes: 5 additions & 9 deletions exec_helpers/subprocess_runner.py
Expand Up @@ -65,29 +65,25 @@ def stdout(self) -> "typing.Optional[typing.IO[bytes]]": # type: ignore
class Subprocess(api.ExecHelper):
"""Subprocess helper with timeouts and lock-free FIFO."""

def __init__(
self,
log_mask_re: typing.Optional[str] = None,
*,
logger: logging.Logger = logging.getLogger(__name__), # noqa: B008
) -> None:
def __init__(self, log_mask_re: typing.Optional[str] = None,) -> None:
"""Subprocess helper with timeouts and lock-free FIFO.
For excluding race-conditions we allow to run 1 command simultaneously
:param log_mask_re: regex lookup rule to mask command for logger.
all MATCHED groups will be replaced by '<*masked*>'
:type log_mask_re: typing.Optional[str]
:param logger: logger instance to use
:type logger: logging.Logger
.. versionchanged:: 1.2.0 log_mask_re regex rule for masking cmd
.. versionchanged:: 3.1.0 Not singleton anymore. Only lock is shared between all instances.
.. versionchanged:: 3.2.0 Logger can be enforced.
.. versionchanged:: 4.1.0 support chroot
.. versionchanged:: 4.3.0 Lock is not shared anymore: allow parallel call of different instances.
"""
super(Subprocess, self).__init__(logger=logger, log_mask_re=log_mask_re)
mod_name = "exec_helpers" if self.__module__.startswith("exec_helpers") else self.__module__
super(Subprocess, self).__init__(
logger=logging.getLogger(f"{mod_name}.{self.__class__.__name__}"), log_mask_re=log_mask_re
)

def _exec_command( # type: ignore
self,
Expand Down

0 comments on commit 89ecb58

Please sign in to comment.