PADFoundationloggingaudittroubleshootingfoundationstructured-logging

Log Detail Writer

Appends a timestamped, leveled log entry to the in-memory log list and optionally writes to a log file. Supports INFO, WARN, and ERROR levels with consistent formatting. Use throughout your flow for structured operational logging.

0 copies

Section 1: Initialize Log Infrastructure

PAD Script
1**REGION Initialize Log Infrastructure
2Variables.CreateNewList List=> lstLogEntries
3SET strLogLevel TO $'''INFO'''
4SET strLogMessage TO $'''REPLACE_WITH_LOG_MESSAGE'''
5SET strRunId TO $'''REPLACE_WITH_RUN_ID'''
6SET strLogFilePath TO $'''(none)'''
7**ENDREGION

Section 2: Format and Append Log Entry

PAD Script
1**REGION Format and Append Log Entry
2DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> dtLogTimestamp
3Text.ConvertDateTimeToText.FromCustomDateTime DateTime: dtLogTimestamp CustomFormat: $'''yyyy-MM-dd HH:mm:ss.fff''' Result=> strLogTimestamp
4SET strFormattedEntry TO $'''[%strLogTimestamp%] [%strLogLevel%] [%strRunId%] %strLogMessage%'''
5Variables.AddItemToList Item: strFormattedEntry List: lstLogEntries NewList=> lstLogEntries
6**ENDREGION

Section 3: Optional File Output

PAD Script
1**REGION Optional File Output
2IF strLogFilePath <> $'''(none)''' THEN
3 File.WriteToCSVFile.WriteCSV VariableToWrite: strFormattedEntry CSVFile: strLogFilePath CsvFileEncoding: File.CSVEncoding.UTF8 IncludeColumnNames: False IfFileExists: File.IfFileExists.Append ColumnsSeparator: File.CSVColumnsSeparator.SystemDefault
4END
5**ENDREGION

Usage Notes

  • Set strLogLevel to INFO, WARN, or ERROR before each call to control the severity tag in the formatted output
  • Set strLogMessage to describe the current operation (e.g., $'''Processing invoice 1042''') before each call
  • strRunId ties every log line back to the current execution — use the value generated by Variable Bootstrap
  • lstLogEntries accumulates all entries in memory; use it at the end of the flow to write a complete log or send via email
  • Each formatted entry follows the pattern: [2026-03-20 14:30:22.150] [INFO] [RUN-20260320-143022] Processing invoice 1042
  • The optional file output (Section 3) appends to a CSV file when strLogFilePath is set to a valid path — leave as (none) to skip file writes
  • For high-volume flows, consider writing to file periodically rather than only keeping entries in memory
  • To use this as a reusable subflow, wrap it in a FUNCTION Subflow_LogDetailWriter GLOBAL block

Requirements

  • lstLogEntries list variable must be initialized (Section 1 handles this, or use Variable Bootstrap)
  • strRunId should be set by the Variable Bootstrap pattern before first use
  • If file output is enabled, the target directory must exist and the flow must have write permissions
  • File.WriteToCSVFile action requires PAD file system actions (included in all PAD versions)
  • No external dependencies — uses only built-in PAD actions