improved subprocess cmd logging

This commit is contained in:
Maxim Devaev 2022-06-19 20:56:51 +03:00
parent 0edf854832
commit 43da6af153
5 changed files with 8 additions and 6 deletions

View File

@ -175,7 +175,7 @@ class JanusRunner: # pylint: disable=too-many-instance-attributes
for part in self.__cmd
]
self.__janus_proc = await aioproc.run_process(cmd)
get_logger(0).info("Started Janus pid=%d: %s", self.__janus_proc.pid, cmd)
get_logger(0).info("Started Janus pid=%d: %s", self.__janus_proc.pid, tools.cmdfmt(cmd))
async def __kill_janus_proc(self) -> None:
if self.__janus_proc:

View File

@ -33,6 +33,7 @@ from typing import Optional
from ....logging import get_logger
from .... import env
from .... import tools
from .... import aiofs
from .... import aioproc
@ -137,10 +138,10 @@ class HwInfoSubmanager(BaseInfoSubmanager):
try:
text = (await aioproc.read_process(cmd, err_to_null=True))[1]
except Exception:
get_logger(0).exception("Error while executing %s", cmd)
get_logger(0).exception("Error while executing: %s", tools.cmdfmt(cmd))
return None
try:
return parser(text)
except Exception as err:
get_logger(0).error("Can't parse %s output: %r: %s", cmd, text, err)
get_logger(0).error("Can't parse [ %s ] output: %r: %s", tools.cmdfmt(cmd), text, tools.efmt(err))
return None

View File

@ -453,7 +453,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
for part in self.__cmd
]
self.__streamer_proc = await aioproc.run_process(cmd)
get_logger(0).info("Started streamer pid=%d: %s", self.__streamer_proc.pid, cmd)
get_logger(0).info("Started streamer pid=%d: %s", self.__streamer_proc.pid, tools.cmdfmt(cmd))
async def __kill_streamer_proc(self) -> None:
if self.__streamer_proc:

View File

@ -131,7 +131,7 @@ class _Service: # pylint: disable=too-many-instance-attributes
async def __run_ctl(self, ctl: BaseCtl, direct: bool) -> bool:
logger = get_logger()
cmd = ctl.get_command(direct)
logger.info("CMD: %s", " ".join(cmd))
logger.info("CMD: %s", tools.cmdfmt(cmd))
try:
return (not (await aioproc.log_process(cmd, logger)).returncode)
except Exception as err:

View File

@ -83,7 +83,8 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
if proc.returncode != 0:
raise RuntimeError(f"Custom command error: retcode={proc.returncode}")
except Exception as err:
get_logger(0).error("Can't run custom command %s: %s", self.__cmd, tools.efmt(err))
get_logger(0).error("Can't run custom command [ %s ]: %s",
tools.cmdfmt(self.__cmd), tools.efmt(err))
raise GpioDriverOfflineError(self)
def __str__(self) -> str: