Skip to content

Commit

Permalink
Merge pull request #452 from xylar/log_command_in_check_call
Browse files Browse the repository at this point in the history
Log commands run with `check_call()` by default
  • Loading branch information
xylar authored Feb 6, 2022
2 parents 0f1adae + 46b8fc6 commit 59512a0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion conda_package/mpas_tools/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess


def check_call(args, logger, **kwargs):
def check_call(args, logger, log_command=True, **kwargs):
"""
Call the given subprocess with logging to the given logger.
Expand All @@ -15,6 +15,9 @@ def check_call(args, logger, **kwargs):
logger : logging.Logger
The logger to write output to
log_command : bool, optional
Whether to write the command that is running ot the logger
kwargs : dict
Keyword arguments to pass to subprocess.Popen
Expand All @@ -25,6 +28,9 @@ def check_call(args, logger, **kwargs):
"""

if log_command:
logger.info(f'Running: {" ".join(args)}')

process = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, **kwargs)
stdout, stderr = process.communicate()
Expand Down

0 comments on commit 59512a0

Please sign in to comment.