Add log messages to the scripts in your PowerShell step. Use log levels for improved logging and debugging.

Before you begin

To add log messages to your script, you will need to use the Write-SNCLog function. This function is defined in the IH\Logging.psm1 module. Use PSScript.ps1 to import this module so inline scripts have access to Write-SNCLog. For more information, see MID Server PowerShell files.

Role required: admin

Procedure

  1. Navigate to All > MID Server > Properties.
  2. Set mid.property.powershell.log_info to true.
    This property enables or disables logging. For more information, see PowerShell log property.
  3. Set mid.property.powershell.ih.log_level to the desired log level.
    The log level specifies the threshold required to log a message. Messages are logged at the specified level or higher. For example, if this property is set to WARN, then messages with a level of WARN or ERROR are logged. Messages with a level of INFO, DEBUG, or TRACE are not logged. The levels, listed from low to high, are:
    • TRACE
    • DEBUG
    • INFO
    • WARN
    • ERROR
    The default value is INFO.
  4. (Optional) Configure a system property so that you can view the logs in the instance.
    1. Navigate to All > Process Automation > Flow Designer > Properties.
    2. Find Specify the log level of system log entries to replicate to the flow log. The system only replicates log entries of the specified level or higher and set it to INFO or DEBUG.

    After the you build and execute the PowerShell script, the logs are available in the MID agent log. Configuring this property also enables you to view them directly in the instance.

    This step sets the com.glide.hub.flow_engine.listener_trace.threshold property. It replicates the logs to the Flow engine log entries [sys_flow_log] table.

  5. In your PowerShell script, add log messages and levels with the Write-SNCLog function.
    Table 1. Write-SNCLog function and parameters
    Name Description
    Write-SNCLog function Log a message for the PowerShell step. Write-SNCLog has two parameters, -Level and -Message. Both parameters are required, but the parameter names are not. If the names are omitted, the position is used to determine the level and message. Examples:
    • Write-SNCLog -Level WARN -Message "log warning"
    • Write-SNCLog WARN "log warning"
    Both of these examples log WARN: log warning.
    -Level parameter Specify the level for the log message. Valid values are:
    • ERROR
    • WARN
    • INFO
    • DEBUG
    • TRACE
    This parameter is required.
    -Message parameter Specify the message to log. Entered as a string. This parameter is required.
  6. Continue building your action or flow, then test and run it.

What to do next

The new logs are available in the MID agent log and can be downloaded from the MID Server. For more information, see Download the MID Server files.

If you set the system property to view the logs in the instance, you can see them in the Flow engine log entries tab of the Flow engine context record. For more information, see Flow execution details.