Log to file package guide
Use Log to File to write text or typed values to a Device file or to the room Run log.
Version 2.17.1. Installed versions can differ. Examples are illustrative and not tested.
Prerequisites
- The Device account must be able to write the file.
- A relative path starts in the Run folder. A full path is used as you give it. Missing folders are created.
- Use test files under
samples, and choose add or replace with care. - Passwords in a Credential are hidden (
********), also in nested values. Plain text and String values are written as you type them, so do not put passwords in text. - Log to Server writes to the Run log in the room. It needs no other server.
Shared fields
| Field | Editor field | Type; default; required/optional | Applies to | Use |
|---|---|---|---|---|
variables | Variables to log | Dictionarydefault {}optional | log, log | A Dictionary of names and values, e.g. $summary$ with Number count= and String status=. Values are written as name=, in the order they were added. Credential passwords are hidden. |
file | File path (Log text), Output file path (Log variables) | Stringdefault ""required | log, log | Log file, e.g. samples/. What happens to old text depends on log. |
append | Append timestamp | Booleandefault falseoptional | log, log | true puts the same local time before each line of the entry, as yyyy-MMM-dd HH:mm:ss ±HHmm. false writes only the text. |
log | When logging | Logdefault APPEND_optional | log, log | APPEND_ keeps the old text and adds the entry. OVERWRITE_ replaces the whole file with this entry. |
Actions
Log to Server (logToFileServer)
Write a message, and optional values, to the Run log in the room.
Inputs
| Input | Editor field | Type; default; required/optional | Use |
|---|---|---|---|
text | Text to log | Stringdefault ""required | Message, e.g. Invoice batch complete. It is written as you type it, so do not put secrets in it. |
tags | Data source tag | Stringdefault ""optional | orders adds [orders] before the message. The whole text is one tag. |
log | Log level | Serverdefault Infooptional | Word put before the message, in capitals: Emergency, Error, Warn, Info or Debug. |
Also uses the shared fields: variables.
Outputs
None.
Example
Prepare Dictionary summary with Number count=3. Set textToLog=step done, tags=orders, logLevel=Warn, variables=$summary$.
Expected result
The Run log gets WARN [orders] step done, then a separate line count=3. An empty Dictionary adds no value lines. If the log cannot be written, the step fails.
Log text to file (logToFileText)
Add or replace a text entry in a Device file. Each line can have a time, and the entry ends with a new line.
Inputs
| Input | Editor field | Type; default; required/optional | Use |
|---|---|---|---|
log | Enter text to log | Stringdefault ""required | Text to write. Each line stays one line, and the entry ends with a new line. The text is not hidden. |
encoding | Encoding | Logdefault UTF8optional | UTF8 is right for most logs. UNICODE and UTF16 write UTF-16 (little-endian). ANSI writes Windows-1252, whatever the Device language. When you add to a log, keep its encoding. |
Also uses the shared fields: filePath, appendTimestamp, logOption.
Outputs
None.
Example
With no samples/run.log yet, set filePath=samples/run.log, logContent=one, appendTimestamp=false, logOption=APPEND_FILE, encodingValue=UTF8. Repeat with logContent=two.
Expected result
The file has the lines one and two, each with a new line. With OVERWRITE_FILE, a third entry three leaves only three and its new line. The step fails if the path is not valid, or the file is locked or cannot be written.
Log variables to file (logToFileVariables)
Write the values of a Dictionary as UTF-8 name=value lines. Credential passwords are hidden.
Inputs
Uses the shared fields: filePath, logOption, appendTimestamp, variables.
Outputs
None.
Example
Prepare Dictionary summary with Number count=7 and String status=ready. Set filePath=samples/variables.log, logOption=OVERWRITE_FILE, appendTimestamp=false, variables=$summary$.
Expected result
The file has count=7 and status=ready on separate lines, in Dictionary order. A Credential shows as username:********. Other text does not change. An empty Dictionary still writes one empty line.