def log_kwds(code=None, cachegroup=None, **kwds):
    """
    Return a set of keywords to be used with every log message.
    Allows `code` and `cachegroup` to be None (and won't log `None` as
    a result), but also logs cachegroup in `code` if `code` is not
    already specified.
    """
    if cachegroup:
        kwds["cachegroup"] = kwds["code"] = cachegroup

    if code:
        kwds["code"] = code

    return kwds