How-To Guides
Flows Guides
Create, Write to, and Read from a Log File
5min
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 docid\ veyyte7xdcangglzbqya0 to learn more drag a write file node and an inject node to the canvas and wire them together 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 action select append to file from the drop down menu and click done 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 from the flows canvas, drag a read file node, inject node, and debug node to the canvas and wire them together 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 done click deploy drag the sidebar up from the bottom of the canvas and select the debug icon click the inject node button to trigger the flow the debug area shows the timestamp that has been written to the /ftp data/testlogfile log file 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, write to, and read from a log file docid\ f52bbwikxrcxu46kj0a5n 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 done 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 drag the sidebar up from the bottom of the canvas and select the debug icon click the inject node button from the read file node configuration to verify that the write task to the pre existing file was successful 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 done 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 drag the sidebar up from the bottom of the canvas and select the debug icon click the inject node button from the read file node configuration to verify that the message was written to the file