@@ -201,7 +201,13 @@ def get_logger(name="Autosubmit") -> None:
201201 logging .getLogger (name )
202202
203203 @staticmethod
204- def set_file (file_path : str , type = 'out' , level = "WARNING" ) -> None :
204+ def set_file (
205+ file_path : str ,
206+ type = "out" ,
207+ level = "WARNING" ,
208+ max_retries : int = 3 ,
209+ timeout : int = 5 ,
210+ ) -> None :
205211 """Configure the file to store the log.
206212
207213 If another file was specified earlier, new messages will only go to the new file.
@@ -210,6 +216,8 @@ def set_file(file_path: str, type='out', level="WARNING") -> None:
210216 :type file_path: str
211217 :param type: file type
212218 :param level: log level
219+ :param max_retries: maximum number of retries to create the log file
220+ :param timeout: time to wait between retries (in seconds)
213221 """
214222 levels = {
215223 "STATUS_FAILED" : 500 ,
@@ -225,9 +233,7 @@ def set_file(file_path: str, type='out', level="WARNING") -> None:
225233
226234 level = levels .get (str (level ).upper (), "DEBUG" )
227235
228- max_retries = 3
229- retries = 1
230- timeout = 5
236+ retries = 0
231237
232238 while not os .path .exists (file_path ) and retries < max_retries :
233239 try :
@@ -271,9 +277,12 @@ def set_file(file_path: str, type='out', level="WARNING") -> None:
271277 status_file_handler .addFilter (custom_filter )
272278 Log .log .addHandler (status_file_handler )
273279 os .chmod (file_path , 509 )
274- except Exception : # retry again
275- Log .warning (f'Unexpected error setting the log file { str (file_path )} , retry { retries } out '
276- f'of { max_retries } : { str (e )} ' )
280+ except Exception as exc : # retry again
281+ retries += 1
282+ if retries >= max_retries :
283+ raise AutosubmitCritical (
284+ message = f"Could not create log file { file_path } after { max_retries } attempts: { exc } "
285+ )
277286 sleep (timeout * retries )
278287
279288 @staticmethod
0 commit comments