Trace files are extensively utilized in Sage X3 software, particularly during lengthy processes like Automatic Invoice Validation or Automatic Work Order Release. When a trace file is displayed, error lines appear in red text, allowing you to navigate through the errors.
To customize a trace file, follow the below steps:
Step 1: We need to open the trace file using the ‘OUVRE_TRACE’ function, as shown in the code below.
![[Open_Trace_Log_File_Code]](https://www.greytrix.com/blogs/sagex3/wp-content/uploads/2024/02/Open_Trace_Log_File_Code-1024x51.png)
Step 2: After opening the log file, we can insert any messages as per our requirements.
Note: To customize a trace file, it’s essential to understand the color codes associated with different messages:
0: Used to display messages in black color.
1: Used to indicate error messages in red color.
-1: Used to present messages in green color.
-2: Used to showcase messages in blue color.
Step 3: Insert a message line using the ‘ECR_TRACE’ function. This function takes two parameters: the first parameter contains the message, and the second contains the color code, as shown in the code below.
![[Inserting_Message_Trace_Log_File_Code]](https://www.greytrix.com/blogs/sagex3/wp-content/uploads/2024/02/Inserting_Message_Trace_Log_File_Code-1024x165.png)
Step 4: After inserting messages, we need to close this trace file using the ‘FERME_TRACE’ function.
![[Close_Trace_Log_File_Code]](https://www.greytrix.com/blogs/sagex3/wp-content/uploads/2024/02/Close_Trace_Log_File_Code-1024x52.png)
Step 5: Now we can display our trace log file using the ‘LEC_TRACE’ function.
![[Display_Trace_Log_File_Code]](https://www.greytrix.com/blogs/sagex3/wp-content/uploads/2024/02/Display_Trace_Log_File_Code-1024x44.png)
Step 6: If you want to delete this trace file, you can use the ‘SUPP_TRACE’ function.
![[Delete_Trace_Log_File_Code]](https://www.greytrix.com/blogs/sagex3/wp-content/uploads/2024/02/Delete_Trace_Log_File_Code-1024x46.png)
After executing this script, you can view the log file as depicted in the screenshot below.
Note: If you added an error message using the code ‘1’ in the ‘ECR_TRACE’ function, you will receive a popup indicating the number of errors before the log file.
![[Number_Of_Errors]](https://www.greytrix.com/blogs/sagex3/wp-content/uploads/2024/02/Number_Of_Errors.png)
![[Log_Reading_Screen]](https://www.greytrix.com/blogs/sagex3/wp-content/uploads/2024/02/Log_Reading_Screen-1024x283.png)
By following the above steps, we can customize the trace log file for errors and success messages.