mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 17:20:30 +08:00
prefix for log_process()
This commit is contained in:
parent
434acc5de5
commit
b6aaf18c42
@ -67,13 +67,16 @@ async def log_process(
|
|||||||
cmd: List[str],
|
cmd: List[str],
|
||||||
logger: logging.Logger,
|
logger: logging.Logger,
|
||||||
env: Optional[Dict[str, str]]=None,
|
env: Optional[Dict[str, str]]=None,
|
||||||
|
prefix: str="",
|
||||||
) -> asyncio.subprocess.Process: # pylint: disable=no-member
|
) -> asyncio.subprocess.Process: # pylint: disable=no-member
|
||||||
|
|
||||||
(proc, stdout) = await read_process(cmd, env=env)
|
(proc, stdout) = await read_process(cmd, env=env)
|
||||||
if stdout:
|
if stdout:
|
||||||
log = (logger.info if proc.returncode == 0 else logger.error)
|
log = (logger.info if proc.returncode == 0 else logger.error)
|
||||||
|
if prefix:
|
||||||
|
prefix += " "
|
||||||
for line in stdout.split("\n"):
|
for line in stdout.split("\n"):
|
||||||
log("=> %s", line)
|
log("%s=> %s", prefix, line)
|
||||||
return proc
|
return proc
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -79,7 +79,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
proc = await aioproc.log_process(self.__cmd, logger=get_logger(0))
|
proc = await aioproc.log_process(self.__cmd, logger=get_logger(0), prefix=str(self))
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise RuntimeError(f"Custom command error: pid={proc.pid}; retcode={proc.returncode}")
|
raise RuntimeError(f"Custom command error: pid={proc.pid}; retcode={proc.returncode}")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
|||||||
@ -153,7 +153,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
return
|
return
|
||||||
action = (_OUTPUTS[pin] if pin.isdigit() else pin)
|
action = (_OUTPUTS[pin] if pin.isdigit() else pin)
|
||||||
try:
|
try:
|
||||||
proc = await aioproc.log_process(**self.__make_ipmitool_kwargs(action), logger=get_logger(0))
|
proc = await aioproc.log_process(**self.__make_ipmitool_kwargs(action), logger=get_logger(0), prefix=str(self))
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise RuntimeError(f"Ipmitool error: pid={proc.pid}; retcode={proc.returncode}")
|
raise RuntimeError(f"Ipmitool error: pid={proc.pid}; retcode={proc.returncode}")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user