Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._internal.utils.logging Namespace Reference

Data Structures

class  BetterRotatingFileHandler
 
class  BrokenStdoutLoggingError
 
class  ExcludeLoggerFilter
 
class  IndentedRenderable
 
class  IndentingFormatter
 
class  MaxLevelFilter
 
class  RichPipStreamHandler
 

Functions

bool _is_broken_pipe_error (Type[BaseException] exc_class, BaseException exc)
 
Generator[None, None, Noneindent_log (int num=2)
 
int get_indentation ()
 
int setup_logging (int verbosity, bool no_color, Optional[str] user_log_file)
 

Variables

 _log_state = threading.local()
 
 subprocess_logger = getLogger("pip.subprocessor")
 

Function Documentation

◆ _is_broken_pipe_error()

bool _is_broken_pipe_error ( Type[BaseException]  exc_class,
BaseException  exc 
)
protected

Definition at line 41 of file logging.py.

41def _is_broken_pipe_error(exc_class: Type[BaseException], exc: BaseException) -> bool:
42 if exc_class is BrokenPipeError:
43 return True
44
45 # On Windows, a broken pipe can show up as EINVAL rather than EPIPE:
46 # https://bugs.python.org/issue19612
47 # https://bugs.python.org/issue30418
48 if not WINDOWS:
49 return False
50
51 return isinstance(exc, OSError) and exc.errno in (errno.EINVAL, errno.EPIPE)
52
53
54@contextlib.contextmanager
for i

Referenced by RichPipStreamHandler.handleError().

Here is the caller graph for this function:

◆ get_indentation()

int get_indentation ( )

Definition at line 69 of file logging.py.

69def get_indentation() -> int:
70 return getattr(_log_state, "indentation", 0)
71
72

References i.

Referenced by RichPipStreamHandler.emit(), IndentingFormatter.format(), and pip._internal.utils.logging.indent_log().

Here is the caller graph for this function:

◆ indent_log()

Generator[None, None, None] indent_log ( int   num = 2)
A context manager which will cause the log output to be indented for any
log messages emitted inside it.

Definition at line 55 of file logging.py.

55def indent_log(num: int = 2) -> Generator[None, None, None]:
56 """
57 A context manager which will cause the log output to be indented for any
58 log messages emitted inside it.
59 """
60 # For thread-safety
61 _log_state.indentation = get_indentation()
63 try:
64 yield
65 finally:
67
68

References pip._internal.utils.logging.get_indentation(), and i.

Here is the call graph for this function:

◆ setup_logging()

int setup_logging ( int  verbosity,
bool  no_color,
Optional[str]  user_log_file 
)
Configures and sets up all of the logging

Returns the requested logging level, as its integer value.

Definition at line 226 of file logging.py.

226def setup_logging(verbosity: int, no_color: bool, user_log_file: Optional[str]) -> int:
227 """Configures and sets up all of the logging
228
229 Returns the requested logging level, as its integer value.
230 """
231
232 # Determine the level to be logging at.
233 if verbosity >= 2:
234 level_number = logging.DEBUG
235 elif verbosity == 1:
236 level_number = VERBOSE
237 elif verbosity == -1:
238 level_number = logging.WARNING
239 elif verbosity == -2:
240 level_number = logging.ERROR
241 elif verbosity <= -3:
242 level_number = logging.CRITICAL
243 else:
244 level_number = logging.INFO
245
246 level = logging.getLevelName(level_number)
247
248 # The "root" logger should match the "console" level *unless* we also need
249 # to log to a user log file.
250 include_user_log = user_log_file is not None
251 if include_user_log:
252 additional_log_file = user_log_file
253 root_level = "DEBUG"
254 else:
255 additional_log_file = "/dev/null"
256 root_level = level
257
258 # Disable any logging besides WARNING unless we have DEBUG level logging
259 # enabled for vendored libraries.
260 vendored_log_level = "WARNING" if level in ["INFO", "ERROR"] else "DEBUG"
261
262 # Shorthands for clarity
263 log_streams = {
264 "stdout": "ext://sys.stdout",
265 "stderr": "ext://sys.stderr",
266 }
267 handler_classes = {
268 "stream": "pip._internal.utils.logging.RichPipStreamHandler",
269 "file": "pip._internal.utils.logging.BetterRotatingFileHandler",
270 }
271 handlers = ["console", "console_errors", "console_subprocess"] + (
272 ["user_log"] if include_user_log else []
273 )
274
276 {
277 "version": 1,
278 "disable_existing_loggers": False,
279 "filters": {
280 "exclude_warnings": {
281 "()": "pip._internal.utils.logging.MaxLevelFilter",
282 "level": logging.WARNING,
283 },
284 "restrict_to_subprocess": {
285 "()": "logging.Filter",
287 },
288 "exclude_subprocess": {
289 "()": "pip._internal.utils.logging.ExcludeLoggerFilter",
291 },
292 },
293 "formatters": {
294 "indent": {
295 "()": IndentingFormatter,
296 "format": "%(message)s",
297 },
298 "indent_with_timestamp": {
299 "()": IndentingFormatter,
300 "format": "%(message)s",
301 "add_timestamp": True,
302 },
303 },
304 "handlers": {
305 "console": {
306 "level": level,
307 "class": handler_classes["stream"],
308 "no_color": no_color,
309 "stream": log_streams["stdout"],
310 "filters": ["exclude_subprocess", "exclude_warnings"],
311 "formatter": "indent",
312 },
313 "console_errors": {
314 "level": "WARNING",
315 "class": handler_classes["stream"],
316 "no_color": no_color,
317 "stream": log_streams["stderr"],
318 "filters": ["exclude_subprocess"],
319 "formatter": "indent",
320 },
321 # A handler responsible for logging to the console messages
322 # from the "subprocessor" logger.
323 "console_subprocess": {
324 "level": level,
325 "class": handler_classes["stream"],
326 "stream": log_streams["stderr"],
327 "no_color": no_color,
328 "filters": ["restrict_to_subprocess"],
329 "formatter": "indent",
330 },
331 "user_log": {
332 "level": "DEBUG",
333 "class": handler_classes["file"],
334 "filename": additional_log_file,
335 "encoding": "utf-8",
336 "delay": True,
337 "formatter": "indent_with_timestamp",
338 },
339 },
340 "root": {
341 "level": root_level,
342 "handlers": handlers,
343 },
344 "loggers": {"pip._vendor": {"level": vendored_log_level}},
345 }
346 )
347
348 return level_number

References i.

Variable Documentation

◆ _log_state

_log_state = threading.local()
protected

Definition at line 31 of file logging.py.

◆ subprocess_logger

subprocess_logger = getLogger("pip.subprocessor")

Definition at line 32 of file logging.py.