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,12 @@ def emit(self, record: logging.LogRecord) -> None:
159
162
else :
160
163
message = self .format (record )
161
164
renderable = self .render_message (record , message )
162
-
165
+ if record .levelno >= logging .ERROR :
166
+ style = Style (color = "red" )
167
+ elif record .levelno >= logging .WARNING :
168
+ style = Style (color = "yellow" )
163
169
try :
164
- self .console .print (renderable , overflow = "ignore" , crop = False )
170
+ self .console .print (renderable , overflow = "ignore" , crop = False , style = style )
165
171
except Exception :
166
172
self .handleError (record )
167
173
@@ -252,7 +258,6 @@ def setup_logging(verbosity: int, no_color: bool, user_log_file: Optional[str])
252
258
"stderr" : "ext://sys.stderr" ,
253
259
}
254
260
handler_classes = {
255
- "subprocess" : "logging.StreamHandler" ,
256
261
"stream" : "pip._internal.utils.logging.RichPipStreamHandler" ,
257
262
"file" : "pip._internal.utils.logging.BetterRotatingFileHandler" ,
258
263
}
@@ -310,8 +315,9 @@ def setup_logging(verbosity: int, no_color: bool, user_log_file: Optional[str])
310
315
# from the "subprocessor" logger.
311
316
"console_subprocess" : {
312
317
"level" : level ,
313
- "class" : handler_classes ["subprocess " ],
318
+ "class" : handler_classes ["stream " ],
314
319
"stream" : log_streams ["stderr" ],
320
+ "no_color" : no_color ,
315
321
"filters" : ["restrict_to_subprocess" ],
316
322
"formatter" : "indent" ,
317
323
},
0 commit comments