@@ -33,7 +33,13 @@ def log_dir(tmpdir_factory):
3333 return str (tmpdir_factory .mktemp ('logs' ))
3434
3535
36- def test_bad_logging_launch_config ():
36+ @pytest .fixture
37+ def mock_clean_env (monkeypatch ):
38+ monkeypatch .delenv ('OVERRIDE_LAUNCH_SCREEN_FORMAT' , raising = False )
39+ monkeypatch .delenv ('OVERRIDE_LAUNCH_LOG_FORMAT' , raising = False )
40+
41+
42+ def test_bad_logging_launch_config (mock_clean_env ):
3743 """Tests that setup throws at bad configuration."""
3844 launch .logging .reset ()
3945
@@ -85,7 +91,7 @@ def test_output_loggers_bad_configuration(log_dir):
8591 },
8692 )
8793])
88- def test_output_loggers_configuration (capsys , log_dir , config , checks ):
94+ def test_output_loggers_configuration (capsys , log_dir , config , checks , mock_clean_env ):
8995 checks = {'stdout' : set (), 'stderr' : set (), 'both' : set (), ** checks }
9096 launch .logging .reset ()
9197 launch .logging .launch_config .log_dir = log_dir
@@ -164,7 +170,7 @@ def test_output_loggers_configuration(capsys, log_dir, config, checks):
164170 assert (not os .path .exists (own_log_path ) or 0 == os .stat (own_log_path ).st_size )
165171
166172
167- def test_screen_default_format_with_timestamps (capsys , log_dir ):
173+ def test_screen_default_format_with_timestamps (capsys , log_dir , mock_clean_env ):
168174 """Test screen logging when using the default logs format with timestamps."""
169175 launch .logging .reset ()
170176 launch .logging .launch_config .level = logging .DEBUG
@@ -183,7 +189,7 @@ def test_screen_default_format_with_timestamps(capsys, log_dir):
183189 assert 0 == len (capture .err )
184190
185191
186- def test_screen_default_format (capsys ):
192+ def test_screen_default_format (capsys , mock_clean_env ):
187193 """Test screen logging when using the default logs format."""
188194 launch .logging .reset ()
189195
@@ -220,6 +226,25 @@ def test_log_default_format(log_dir):
220226 assert re .match (r'[0-9]+\.[0-9]+ \[ERROR\] \[some-proc\]: baz' , lines [0 ]) is not None
221227
222228
229+ def test_logging_env_var_format (capsys , monkeypatch ):
230+ monkeypatch .setenv ('OVERRIDE_LAUNCH_SCREEN_FORMAT' , 'TESTSCREEN {message} {name} TESTSCREEN' )
231+ monkeypatch .setenv ('OVERRIDE_LAUNCH_LOG_FORMAT' , 'TESTLOG {message} {name} TESTLOG' )
232+ launch .logging .reset ()
233+
234+ logger = launch .logging .get_logger ('some-proc' )
235+ logger .addHandler (launch .logging .launch_config .get_screen_handler ())
236+
237+ logger .info ('bar' )
238+ capture = capsys .readouterr ()
239+ lines = capture .out .splitlines ()
240+ assert 'TESTSCREEN bar some-proc TESTSCREEN' == lines .pop ()
241+
242+ launch .logging .launch_config .get_log_file_handler ().flush ()
243+ with open (launch .logging .launch_config .get_log_file_path (), 'r' ) as f :
244+ lines = f .readlines ()
245+ assert 'TESTLOG bar some-proc TESTLOG\n ' == lines [0 ]
246+
247+
223248def test_log_handler_factory (log_dir ):
224249 """Test logging using a custom log handlers."""
225250 class TestStreamHandler (launch .logging .handlers .Handler ):
0 commit comments