Skip to content

Commit 1aa1d17

Browse files
use custom log_file name as per the user setting
Signed-off-by: Tanishq Chaudhary <[email protected]>
1 parent ccccd4f commit 1aa1d17

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

launch/launch/launch_service.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def __init__(
5555
*,
5656
argv: Optional[Iterable[Text]] = None,
5757
noninteractive: bool = False,
58-
debug: bool = False
58+
debug: bool = False,
59+
log_file_name: Optional[Text] = None
5960
) -> None:
6061
"""
6162
Create a LaunchService.
@@ -67,6 +68,9 @@ def __init__(
6768
"""
6869
# Setup logging and debugging.
6970
launch.logging.launch_config.level = logging.DEBUG if debug else logging.INFO
71+
# Set the log file name.
72+
if log_file_name is not None:
73+
launch.logging.launch_config.file_name = log_file_name
7074
self.__debug = debug
7175
self.__argv = argv if argv is not None else []
7276

launch/launch/logging/__init__.py

+13
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def reset(self):
113113
self.screen_formatter = None
114114
self.file_formatter = None
115115
self._log_handler_factory = None
116+
self._file_name = 'launch.log'
116117
logging.root.setLevel(logging.INFO)
117118
self.set_screen_format('default')
118119
self.set_log_format('default')
@@ -130,6 +131,17 @@ def level(self, new_level):
130131
"""
131132
logging.root.setLevel(new_level)
132133

134+
@property
135+
def file_name(self) -> str:
136+
"""Get the current log file name."""
137+
return self._file_name
138+
139+
@file_name.setter
140+
def file_name(self, new_file_name: str):
141+
"""Set the current log file name."""
142+
if new_file_name is not None:
143+
self._file_name = new_file_name
144+
133145
@property
134146
def log_dir(self):
135147
"""Get the current log directory, generating it if necessary."""
@@ -307,6 +319,7 @@ def get_log_file_path(self, file_name='launch.log'):
307319
:param: file_name of the log file from which to get the absolute path.
308320
:return: the absolute path to the log file.
309321
"""
322+
file_name = self.file_name
310323
return os.path.join(self.log_dir, file_name)
311324

312325
def get_log_file_handler(self, file_name='launch.log'):

0 commit comments

Comments
 (0)