18
18
from pip ._vendor .rich .highlighter import NullHighlighter
19
19
from pip ._vendor .rich .logging import RichHandler
20
20
from pip ._vendor .rich .segment import Segment
21
+ from pip ._vendor .rich .style import Style
21
22
22
23
from pip ._internal .exceptions import DiagnosticPipError
23
24
from pip ._internal .utils ._log import VERBOSE , getLogger
@@ -148,6 +149,8 @@ def __init__(self, stream: Optional[TextIO], no_color: bool) -> None:
148
149
149
150
# Our custom override on rich's logger, to make things work as we need them to.
150
151
def emit (self , record : logging .LogRecord ) -> None :
152
+ style : Optional [Style ] = None
153
+
151
154
# If we are given a diagnostic error to present, present it with indentation.
152
155
if record .msg == "[present-diagnostic]" and len (record .args ) == 1 :
153
156
diagnostic_error : DiagnosticPipError = record .args [0 ] # type: ignore[index]
@@ -159,9 +162,14 @@ def emit(self, record: logging.LogRecord) -> None:
159
162
else :
160
163
message = self .format (record )
161
164
renderable = self .render_message (record , message )
165
+ if record .levelno is not None :
166
+ if record .levelno >= logging .ERROR :
167
+ style = Style (color = "red" )
168
+ elif record .levelno >= logging .WARNING :
169
+ style = Style (color = "yellow" )
162
170
163
171
try :
164
- self .console .print (renderable , overflow = "ignore" , crop = False )
172
+ self .console .print (renderable , overflow = "ignore" , crop = False , style = style )
165
173
except Exception :
166
174
self .handleError (record )
167
175
@@ -252,7 +260,6 @@ def setup_logging(verbosity: int, no_color: bool, user_log_file: Optional[str])
252
260
"stderr" : "ext://sys.stderr" ,
253
261
}
254
262
handler_classes = {
255
- "subprocess" : "logging.StreamHandler" ,
256
263
"stream" : "pip._internal.utils.logging.RichPipStreamHandler" ,
257
264
"file" : "pip._internal.utils.logging.BetterRotatingFileHandler" ,
258
265
}
@@ -310,8 +317,9 @@ def setup_logging(verbosity: int, no_color: bool, user_log_file: Optional[str])
310
317
# from the "subprocessor" logger.
311
318
"console_subprocess" : {
312
319
"level" : level ,
313
- "class" : handler_classes ["subprocess " ],
320
+ "class" : handler_classes ["stream " ],
314
321
"stream" : log_streams ["stderr" ],
322
+ "no_color" : no_color ,
315
323
"filters" : ["restrict_to_subprocess" ],
316
324
"formatter" : "indent" ,
317
325
},
0 commit comments