@@ -271,6 +271,13 @@ def __init__(self, config):
271
271
create a single one for the entire test session here.
272
272
"""
273
273
self ._config = config
274
+
275
+ # enable verbose output automatically if live logging is enabled
276
+ if self ._config .getini ('log_cli' ) and not config .getoption ('verbose' ):
277
+ # sanity check: terminal reporter should not have been loaded at this point
278
+ assert self ._config .pluginmanager .get_plugin ('terminalreporter' ) is None
279
+ config .option .verbose = 1
280
+
274
281
self .print_logs = get_option_ini (config , 'log_print' )
275
282
self .formatter = logging .Formatter (
276
283
get_option_ini (config , 'log_format' ),
@@ -352,7 +359,7 @@ def _setup_cli_logging(self):
352
359
"""
353
360
terminal_reporter = self ._config .pluginmanager .get_plugin ('terminalreporter' )
354
361
if self ._config .getini ('log_cli' ) and terminal_reporter is not None :
355
- log_cli_handler = logging . StreamHandler (terminal_reporter ._tw )
362
+ log_cli_handler = _LiveLoggingStreamHandler (terminal_reporter ._tw )
356
363
log_cli_format = get_option_ini (
357
364
self ._config , 'log_cli_format' , 'log_format' )
358
365
log_cli_date_format = get_option_ini (
@@ -368,3 +375,18 @@ def _setup_cli_logging(self):
368
375
else :
369
376
self .log_cli_handler = None
370
377
self .live_logs_context = _dummy_context_manager ()
378
+
379
+
380
+ class _LiveLoggingStreamHandler (logging .StreamHandler ):
381
+ """
382
+ Custom StreamHandler used by the live logging feature: it will write a newline before the first log message
383
+ in each test.
384
+ """
385
+
386
+ def emit (self , record ):
387
+ if not getattr (self , '_first_record_emitted' , False ):
388
+ self .stream .write ('\n ' )
389
+ # we might consider adding a header at this point using self.stream.sep('-', 'live log') or something
390
+ # similar when we improve live logging output
391
+ self ._first_record_emitted = True
392
+ logging .StreamHandler .emit (self , record )
0 commit comments