Better, smarter call logic

def call(command, stdin=None, stdout=subprocess.PIPE, env=os.environ, cwd=None,
         shell=False, output_log_level=logging.INFO, sensitive_info=False):
    """ Better, smarter call logic """
    if not sensitive_info:
        logger.debug("calling command: %s" % command)
    else:
        logger.debug("calling command with sensitive information")
    try:
        args = command if shell else whitespace_smart_split(command)
        kw = {}
        if not shell and not which(args[0], cwd=cwd):
            raise CommandMissingException(args[0])
        if shell:
            kw['shell'] = True
        process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=stdout,
                                   stderr=subprocess.STDOUT, env=env, cwd=cwd,
                                   **kw)
        output = process.communicate(input=stdin)[0]
        if output is not None:
            try:
                logger.log(output_log_level, output.decode('utf-8'))
            except UnicodeDecodeError:
                pass
        return (process.returncode, output)
    except OSError:
        e = sys.exc_info()[1]
        if not sensitive_info:
            logger.exception("Error running command: %s" % command)
            logger.error("Root directory: %s" % cwd)
            if stdin:
                logger.error("stdin: %s" % stdin)
        raise e