1# Copyright (c) 2022 Nordic Semiconductor ASA 2# SPDX-License-Identifier: Apache-2.0 3 4''' 5Common code used when logging that is needed by multiple modules. 6''' 7 8import platform 9import shlex 10 11_WINDOWS = (platform.system() == 'Windows') 12 13def log_command(logger, msg, args): 14 '''Platform-independent helper for logging subprocess invocations. 15 Will log a command string that can be copy/pasted into a POSIX 16 shell on POSIX platforms. This is not available on Windows, so 17 the entire args array is logged instead. 18 19 :param logger: logging.Logger to use 20 :param msg: message to associate with the command 21 :param args: argument list as passed to subprocess module 22 ''' 23 msg = f'{msg}: %s' 24 if _WINDOWS: 25 logger.debug(msg, str(args)) 26 else: 27 logger.debug(msg, shlex.join(args)) 28