In this article, we will take a closer look at how you can write log files in Foxtrot. Logs are .csv files that are created by Foxtrot with the use of the Write Log Action. Logs allow for the recording of certain events or information from a Project in real time. For example, if you are interested in logging every time the execution handles a record, you can you the Write Log action at the end of the loop to store this information. Typically, you also use the functionality of the log to store information about errors or unexpected events.
Set up logs
To set up logs in Foxtrot is very easy. It requires three simple steps:
- Make sure to create all the variables relevant to the log. It is also recommended to run the project until you reach the point in the process where you actually want to write to the log. This way, you will get a realistic example of what the output of the log will be when the Write Log action is executed.
- In the project pane, click to add a log. Configure the log by setting the name, path, items to be included, and the additional options.
- Whenever you wish to write to the log, use the Write Log action. The Write Log action will always simply append rows to the CSV file.
- If you ever wish to clear the content of the log, simply use the Clear Log action.
In the attached file (find at the end of the article), you can find an example of how to build a script using Logs. You can download the script and try to run it. Remember to save the Foxtrot Project File to the same location as your other projects, typically in this destination: C:\ProgramData\Foxtrot Suite
This is the full project:
In this project, as an example, we are first creating a simple blank workbook to write 30 different values in separate rows. Hereafter, we loop through the rows to retrieve the random value and depending on whether the value is more than 50000 or less than 50000, we write to two different log (CSV) files. To set up your logs, first, make sure that you have created all the relevant variables and is positioned where you would like to write to the log. In this case, you want to be here as we then have both the variable "Value" created and with some data plus we have the loop activated with the current loop number token:
To create the log, click on the plus icon in the project pane and select "Log".
Then, you fill out the information about the log:
- Name = Simply the name of the log, something that describes the purpose of the log. For example, it could be "Error Log".
- File path = The folder and file name of the CSV file to be created. Remember to append ".csv"!
- Items = Then you add the items; variables, tokens, or other values that you wish to include in the log by clicking the plus icon.
- Add header = This controls whether you would like to include the names of the items as the first row in the log.
- Add custom message to each row = When enabled, you are able to include a custom value as the last column whenever you use the Write Log action.
- Custom delimiter = By default, the delimiter of the log is a comma. If you have regional settings that use, for example, semi-colon in Excel, you can set the delimiter to be semi-colon instead here.
In this project example, this is how the logs are setup. Notice that ".csv" is appended in the file path and the arrow indicates where you click to add items:
If we look at the Write Log actions, this is how they are set up. Notice that since the custom message is enabled, it is possible to include a string with any values that you would like:
Note that you can exactly write to multiple logs with a single Write Log action if that is relevant.