Configure logging for flake8. :param verbosity: How verbose to be in logging information. :param filename: Name of the file to append log information to. If ``None`` this will log to ``sys.stderr``. If the name is "stdout" or "stderr" this will log to the app
(
verbosity: int,
filename: str | None = None,
logformat: str = LOG_FORMAT,
)
| 34 | |
| 35 | |
| 36 | def configure_logging( |
| 37 | verbosity: int, |
| 38 | filename: str | None = None, |
| 39 | logformat: str = LOG_FORMAT, |
| 40 | ) -> None: |
| 41 | """Configure logging for flake8. |
| 42 | |
| 43 | :param verbosity: |
| 44 | How verbose to be in logging information. |
| 45 | :param filename: |
| 46 | Name of the file to append log information to. |
| 47 | If ``None`` this will log to ``sys.stderr``. |
| 48 | If the name is "stdout" or "stderr" this will log to the appropriate |
| 49 | stream. |
| 50 | """ |
| 51 | if verbosity <= 0: |
| 52 | return |
| 53 | |
| 54 | verbosity = min(verbosity, max(_VERBOSITY_TO_LOG_LEVEL)) |
| 55 | log_level = _VERBOSITY_TO_LOG_LEVEL[verbosity] |
| 56 | |
| 57 | if not filename or filename in ("stderr", "stdout"): |
| 58 | fileobj = getattr(sys, filename or "stderr") |
| 59 | handler_cls: type[logging.Handler] = logging.StreamHandler |
| 60 | else: |
| 61 | fileobj = filename |
| 62 | handler_cls = logging.FileHandler |
| 63 | |
| 64 | handler = handler_cls(fileobj) |
| 65 | handler.setFormatter(logging.Formatter(logformat)) |
| 66 | LOG.addHandler(handler) |
| 67 | LOG.setLevel(log_level) |
| 68 | LOG.debug( |
| 69 | "Added a %s logging handler to logger root at %s", filename, __name__, |
| 70 | ) |
nothing calls this directly
no outgoing calls
no test coverage detected