Skip to content

Commit edb57b1

Browse files
launch service constructor test for custom naming of log_file_name and logger_name
Signed-off-by: Tanishq Chaudhary <[email protected]>
1 parent b91bbdc commit edb57b1

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

launch/launch/launch_service.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ def __init__(
6868
"""
6969
# Setup logging and debugging.
7070
launch.logging.launch_config.level = logging.DEBUG if debug else logging.INFO
71-
if log_file_name is None:
72-
log_file_name = 'launch'
71+
self._log_file_name = log_file_name
72+
if self._log_file_name is None:
73+
self._log_file_name = 'launch'
7374
# Ensure the log file name ends with `.log`
74-
if not log_file_name.endswith('.log'):
75-
log_file_name += '.log'
76-
launch.logging.launch_config.log_file_name = log_file_name
75+
if not self._log_file_name.endswith('.log'):
76+
self._log_file_name += '.log'
77+
launch.logging.launch_config.log_file_name = self._log_file_name
7778
# Setup logging
78-
logger_name = log_file_name.removesuffix('.log')
79-
self.__logger = launch.logging.get_logger(logger_name)
79+
self._logger_name = self._log_file_name.removesuffix('.log')
80+
self.__logger = launch.logging.get_logger(self._logger_name)
8081

8182
self.__debug = debug
8283
self.__argv = argv if argv is not None else []

launch/test/launch/test_launch_service.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@
2626

2727
def test_launch_service_constructors():
2828
"""Test the constructors for LaunchService class."""
29-
LaunchService()
29+
# When no name is provided for log file
30+
ls = LaunchService()
31+
assert ls._log_file_name == 'launch.log'
32+
assert ls._logger_name == 'launch'
33+
# WHen log file name is provided without .log
34+
ls = LaunchService(log_file_name='custom_logger')
35+
assert ls._log_file_name == 'custom_logger.log'
36+
assert ls._logger_name == 'custom_logger'
37+
# When log file name is provided with .log
38+
ls = LaunchService(log_file_name='custom_logger.log')
39+
assert ls._log_file_name == 'custom_logger.log'
40+
assert ls._logger_name == 'custom_logger'
3041
LaunchService(debug=True)
3142
LaunchService(debug=False)
3243

0 commit comments

Comments
 (0)