@@ -1142,7 +1142,9 @@ def get_output_file_path(self, file_name: str, prefix: str | bool = None) -> Pat
11421142 file_name = f"{ prefix } -{ file_name } "
11431143 return self .filesystem .get_output_dir ().joinpath (file_name )
11441144
1145- def get_log_file_path (self , file_name : str , prefix : bool = True ) -> Path :
1145+ def get_log_file_path (
1146+ self , file_name : str , prefix : bool = True , timestamped : bool = False
1147+ ) -> Path :
11461148 """
11471149 Get the log file path for this process.
11481150
@@ -1159,6 +1161,10 @@ def get_log_file_path(self, file_name: str, prefix: bool = True) -> Path:
11591161 value of the prefix id drawn from the "log_file_prefix" key within
11601162 this state. If that key is not set, no prefix is added regardless
11611163 of the value of this argument.
1164+ timestamped : bool, default False
1165+ Whether to add a timestamp to the log file name. If True, a
1166+ timestamp is added as a directory prefix to the log file name,
1167+ and the directory is created if it does not already exist.
11621168
11631169 Returns
11641170 -------
@@ -1167,6 +1173,19 @@ def get_log_file_path(self, file_name: str, prefix: bool = True) -> Path:
11671173 prefix = prefix and self .get_injectable ("log_file_prefix" , None )
11681174 if prefix :
11691175 file_name = f"{ prefix } -{ file_name } "
1176+ if timestamped :
1177+ from datetime import datetime
1178+
1179+ timestamp = self .get ("run_timestamp" , None )
1180+ if timestamp is None :
1181+ # if no run timestamp, use current time, and store it so
1182+ # it can be used later in the same run
1183+ timestamp = datetime .now ().strftime ("%Y%m%d-%H%M%S" )
1184+ self .set ("run_timestamp" , timestamp )
1185+ self .filesystem .get_log_file_path (timestamp ).mkdir (
1186+ parents = True , exist_ok = True
1187+ )
1188+ file_name = os .path .join (timestamp , file_name )
11701189 return self .filesystem .get_log_file_path (file_name )
11711190
11721191 def set_step_args (self , args = None ):
0 commit comments