def METHOD_NAME(self, value, param, ctx):
    if value is None:
        return value
    try:
        return int(value)
    except ValueError:
        vupper = value.upper()
        if vupper in self.levels:
            return getattr(logging, vupper)
        else:
            self.fail(f"{value!r}: invalid log level", param, ctx)