Create, Write to, and Read from a Log File
5 min
You can use Flows to create a log file on the Litmus Edge device, populate it, and read its contents.
Note: File names used in node configurations are case sensitive.
Create a Log File
Before any data can be written, you need to create create a file first.
To create a file in a flow:
- In Litmus Edge, navigate to the Flows Manager and create a new flow. See Create a Flow to learn more.
- Double-click the write file node. The Edit write file node dialog box appears.
- Filename: Enter a filename prefaced with a forward slash ( / ).
- The forward slash is required in the filename. Example: /ftp-data/testlogfile.log
- The file is created on the Litmus Edge device.
- If a subdirectory already exists, you can supply the full path to the file. Example: /ftp-data/testlogfile or /logfiles/testlogfile.
- Click Deploy to save the flow.
- Click the button on the left side of the inject (timestamp) node to inject the current timestamp into the write file node, which creates the file locally if it does not already exist. In this example, the /ftp-data/testlogfile.log file is saved.
Read a File
You can use a Read file node to access a file that you have created or written to.
To read a file:
- Double-click the read file node. The Edit read file node dialog box appears.
- Filename: Enter the filename prefaced with a forward slash ( / ). A forward slash is required to be the first character of the filename. Example: /ftp-data/testlogfile.log
- Output: From the drop-down menu, select the standard single utf8 string format.
- Click Deploy.
Write to a Pre-Existing File
In the Create a Log File steps, the inject node triggered file creation. The following steps show how to write to an existing file.
To continue writing to the file that was created in Create a Log File:
- From the Flows canvas, double-click the write file node. The Edit write file node dialog box appears.
- Filename: Enter a filename prefaced with a forward slash ( / ). We use the same file we created before: /ftp-data/testlogfile.log
- Action: Select append to file from the drop-down menu.
- Click Deploy.
- Click the inject node button to inject the current timestamp into the write file node, which appends the output to the pre-existing file.
Write a Message to a File
You can inject a string message into a pre-existing or a new file from the Flows.
To write a message (text string) to a file:
- In your Flow canvas, double-click the inject node. The Edit inject node dialog box appears.
- msg.payload: From the drop-down menu, select String.
- Enter text of your choice in the blank text field. In this example, we have entered: Hello World.
- Click Deploy.
- Click the inject node button to inject the message into the write file node, which appends the output to the pre-existing file.










