import os
def extend_file_path_for_diagnostics(file_path, diagnostic_level="INFO"):
"""
Extends a file path for diagnostics by adding a diagnostic level indicator.
Args:
file_path (str): The original file path.
diagnostic_level (str, optional): The diagnostic level (e.g., "INFO", "WARNING", "ERROR"). Defaults to "INFO".
Returns:
str: The extended file path with the diagnostic level.
"""
# Ensure the file path is a string
file_path = str(file_path)
# Extract the directory from the file path
directory = os.path.dirname(file_path)
# Extract the file name from the file path
file_name = os.path.basename(file_path)
# Create the diagnostic level string
diagnostic_string = f"[{diagnostic_level}]"
# Construct the extended file path
extended_file_path = os.path.join(directory, diagnostic_string + file_name)
return extended_file_path
if __name__ == '__main__':
# Example Usage
original_path = "my_data/report.txt"
extended_path = extend_file_path_for_diagnostics(original_path, "DEBUG")
print(f"Original path: {original_path}")
print(f"Extended path: {extended_path}")
original_path = "/path/to/log.file"
extended_path = extend_file_path_for_diagnostics(original_path) # uses default INFO level
print(f"Original path: {original_path}")
print(f"Extended path: {extended_path}")
Add your comment