@@ -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,30 @@ 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 ()
95
106
launch .logging .launch_config .log_dir = log_dir
96
- logger = launch .logging .get_logger ('some-proc' )
107
+ if main_log_file_name is None :
108
+ main_log_file_name = launch .logging .launch_config .log_file_name
109
+ logger_name = main_log_file_name .removesuffix ('.log' )
110
+ logger = launch .logging .get_logger (logger_name , main_log_file_name )
97
111
logger .addHandler (launch .logging .launch_config .get_screen_handler ())
98
- logger .addHandler (launch .logging .launch_config .get_log_file_handler ())
112
+ logger .addHandler (launch .logging .launch_config .get_log_file_handler (main_log_file_name ))
99
113
logger .setLevel (logging .ERROR )
100
- stdout_logger , stderr_logger = launch .logging .get_output_loggers ('some-proc' , config )
114
+ stdout_logger , stderr_logger = launch .logging .get_output_loggers ('some-proc' , config , main_log_file_name )
101
115
102
116
logger .debug ('oops' )
103
117
logger .error ('baz' )
@@ -106,21 +120,22 @@ def test_output_loggers_configuration(capsys, log_dir, config, checks, mock_clea
106
120
107
121
capture = capsys .readouterr ()
108
122
lines = list (reversed (capture .out .splitlines ()))
109
- assert '[ERROR] [some-proc ]: baz' == lines .pop ()
123
+ assert f '[ERROR] [{ logger_name } ]: baz' == lines .pop ()
110
124
if 'screen' in (checks ['stdout' ] | checks ['both' ]):
111
125
assert 'foo' == lines .pop ()
112
126
if 'screen' in (checks ['stderr' ] | checks ['both' ]):
113
127
assert 'bar' == lines .pop ()
114
128
assert 0 == len (lines )
115
129
assert 0 == len (capture .err )
116
130
117
- launch .logging .launch_config .get_log_file_handler ().flush ()
118
- main_log_path = launch .logging .launch_config .get_log_file_path ()
131
+ launch .logging .launch_config .get_log_file_handler (main_log_file_name ).flush ()
132
+ main_log_path = launch .logging .launch_config .get_log_file_path (main_log_file_name )
119
133
assert os .path .exists (main_log_path )
120
134
assert 0 != os .stat (main_log_path ).st_size
121
135
with open (main_log_path , 'r' ) as f :
122
136
lines = list (reversed (f .readlines ()))
123
- assert re .match (r'[0-9]+\.[0-9]+ \[ERROR\] \[some-proc\]: baz' , lines .pop ()) is not None
137
+ assert re .match (rf'[0-9]+\.[0-9]+ \[ERROR\] \[{ logger_name } \]: baz' ,
138
+ lines .pop ()) is not None
124
139
if 'log' in (checks ['stdout' ] | checks ['both' ]):
125
140
assert re .match (r'[0-9]+\.[0-9]+ foo' , lines .pop ()) is not None
126
141
if 'log' in (checks ['stderr' ] | checks ['both' ]):
0 commit comments