import inspect


def excludeFromLogging(frame):
    """
    Check whether frame shall be excluded from logging.

    This is the case if the module of the frame itself or on of its outer frames
    belongs to the inspect or logging infrastructure
    """
    if not frame:
        return False

    module = inspect.getmodule(frame)
    if not module:
        return False

    moduleName = module.__name__

    if (moduleName == "inspect") \
    or (moduleName == "logging") \
    or (moduleName == __name__):
        #Do not log inside infrastructure modules
        return True
    else:
        oframe = frame.f_back
        if not oframe:
            return False
        return excludeFromLogging(oframe)