@@ -67,7 +67,7 @@ def test_output_loggers_bad_configuration(log_dir):
67
67
launch .logging .get_output_loggers ('some-proc' , {'stdout' : {'garbage' }})
68
68
69
69
70
- @ pytest . mark . parametrize ( 'config,checks' , [
70
+ configs = [
71
71
('screen' , {'stdout' : {'screen' }, 'stderr' : {'screen' }}),
72
72
('log' , {'stdout' : {'log' }, 'stderr' : {'log' , 'screen' }}),
73
73
('both' , {'both' : {'log' , 'screen' }}),
@@ -88,16 +88,32 @@ def test_output_loggers_bad_configuration(log_dir):
88
88
'stderr' : {'own_log' }
89
89
},
90
90
)
91
- ])
92
- def test_output_loggers_configuration (capsys , log_dir , config , checks , mock_clean_env ):
91
+ ]
92
+ log_file_names = ['custom-log-name.log' , None ]
93
+ params = [
94
+ (config , checks , log_file_name )
95
+ for (config , checks ) in configs
96
+ for log_file_name in log_file_names
97
+ ]
98
+
99
+
100
+ @pytest .mark .parametrize ('config,checks,main_log_file_name' , params )
101
+ def test_output_loggers_configuration (
102
+ capsys , log_dir , config , checks , main_log_file_name , mock_clean_env
103
+ ):
93
104
checks = {'stdout' : set (), 'stderr' : set (), 'both' : set (), ** checks }
94
105
launch .logging .reset ()
106
+ if main_log_file_name is None :
107
+ main_log_file_name = launch .logging .launch_config .log_file_name
108
+ logger_name = main_log_file_name .removesuffix ('.log' )
95
109
launch .logging .launch_config .log_dir = log_dir
96
- logger = launch .logging .get_logger ('some-proc' )
110
+ launch .logging .launch_config .log_file_name = main_log_file_name
111
+ logger = launch .logging .get_logger (logger_name )
97
112
logger .addHandler (launch .logging .launch_config .get_screen_handler ())
98
113
logger .addHandler (launch .logging .launch_config .get_log_file_handler ())
99
114
logger .setLevel (logging .ERROR )
100
- stdout_logger , stderr_logger = launch .logging .get_output_loggers ('some-proc' , config )
115
+ stdout_logger , stderr_logger = launch .logging .get_output_loggers (
116
+ 'some-proc' , config , main_log_file_name )
101
117
102
118
logger .debug ('oops' )
103
119
logger .error ('baz' )
@@ -106,21 +122,22 @@ def test_output_loggers_configuration(capsys, log_dir, config, checks, mock_clea
106
122
107
123
capture = capsys .readouterr ()
108
124
lines = list (reversed (capture .out .splitlines ()))
109
- assert '[ERROR] [some-proc ]: baz' == lines .pop ()
125
+ assert f '[ERROR] [{ logger_name } ]: baz' == lines .pop ()
110
126
if 'screen' in (checks ['stdout' ] | checks ['both' ]):
111
127
assert 'foo' == lines .pop ()
112
128
if 'screen' in (checks ['stderr' ] | checks ['both' ]):
113
129
assert 'bar' == lines .pop ()
114
130
assert 0 == len (lines )
115
131
assert 0 == len (capture .err )
116
132
117
- launch .logging .launch_config .log_file_name = 'launch.log'
133
+ launch .logging .launch_config .log_file_name = main_log_file_name
118
134
main_log_path = launch .logging .launch_config .get_log_file_path ()
119
135
assert os .path .exists (main_log_path )
120
136
assert 0 != os .stat (main_log_path ).st_size
121
137
with open (main_log_path , 'r' ) as f :
122
138
lines = list (reversed (f .readlines ()))
123
- assert re .match (r'[0-9]+\.[0-9]+ \[ERROR\] \[some-proc\]: baz' , lines .pop ()) is not None
139
+ assert re .match (rf'[0-9]+\.[0-9]+ \[ERROR\] \[{ logger_name } \]: baz' ,
140
+ lines .pop ()) is not None
124
141
if 'log' in (checks ['stdout' ] | checks ['both' ]):
125
142
assert re .match (r'[0-9]+\.[0-9]+ foo' , lines .pop ()) is not None
126
143
if 'log' in (checks ['stderr' ] | checks ['both' ]):
0 commit comments