Skip to main content
Version: 1.4.0

Print

Mutate String Formatting

Synopsis

Creates formatted strings using template values and field references.

Schema

- print:
format: <string>
values: <array>
field: <ident>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>

Configuration

The following fields are used to define the processor:

FieldRequiredDefaultDescription
formatY-Printf-style format string with %s placeholders
valuesY-Array of values or field references to substitute
fieldY-Target field to store formatted result
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue processing if formatting fails
ignore_missingNfalseSkip processing if referenced fields don't exist
on_failureN-See Handling Failures
on_successN-See Handling Success
tagN-Identifier

Details

Creates formatted strings by substituting values into printf-style format strings. The processor supports both literal values and dynamic field references using template syntax.

Values in the values array can be literal strings or field references using triple-brace template syntax ({{{field_name}}}). The processor resolves field references before substituting into the format string.

note

The processor uses Go's fmt.Sprintf formatting with %s placeholders. The number of %s placeholders in the format string should match the number of values provided. Extra values are truncated, missing values are padded with empty strings.

When ignore_missing is enabled, missing field references resolve to empty strings rather than causing processor failure. This allows graceful handling of optional fields in templates.

warning

Template resolution occurs before format substitution. Ensure field references use correct triple-brace syntax ({{{field}}}) to avoid literal text substitution instead of field value resolution.

Examples

Basic String Formatting

Creating formatted message with literal values...

{
"user_id": 12345,
"action": "login"
}
- print:
format: "User %s performed action: %s"
values: ["john.doe", "login"]
field: log_message

generates formatted string:

{
"user_id": 12345,
"action": "login",
"log_message": "User john.doe performed action: login"
}

Dynamic Field References

Using field references in format values...

{
"username": "alice",
"ip_address": "192.168.1.100",
"timestamp": "2024-01-15T10:30:00Z"
}
- print:
format: "[%s] User %s connected from %s"
values: ["{{{timestamp}}}", "{{{username}}}", "{{{ip_address}}}"]
field: connection_log

resolves field values into format:

{
"username": "alice",
"ip_address": "192.168.1.100",
"timestamp": "2024-01-15T10:30:00Z",
"connection_log": "[2024-01-15T10:30:00Z] User alice connected from 192.168.1.100"
}

Alert Message Generation

Creating alert messages from event data...

{
"severity": "HIGH",
"event_type": "failed_login",
"source_ip": "10.0.0.50",
"attempts": 5
}
- print:
format: "ALERT: %s severity %s from %s (%s attempts)"
values: ["{{{event_type}}}", "{{{severity}}}", "{{{source_ip}}}", "{{{attempts}}}"]
field: alert_message

formats comprehensive alert:

{
"severity": "HIGH",
"event_type": "failed_login",
"source_ip": "10.0.0.50",
"attempts": 5,
"alert_message": "ALERT: failed_login severity HIGH from 10.0.0.50 (5 attempts)"
}

Report Summary Creation

Generating summary reports from metrics...

{
"total_events": 15847,
"errors": 23,
"warnings": 156,
"processing_time": "2.3s"
}
- print:
format: "Processed %s events (%s errors, %s warnings) in %s"
values: ["{{{total_events}}}", "{{{errors}}}", "{{{warnings}}}", "{{{processing_time}}}"]
field: summary_report

creates processing summary:

{
"total_events": 15847,
"errors": 23,
"warnings": 156,
"processing_time": "2.3s",
"summary_report": "Processed 15847 events (23 errors, 156 warnings) in 2.3s"
}

Mixed Literal and Dynamic Values

Combining literal text with field values...

{
"service": "authentication",
"status": "operational",
"uptime": 99.97
}
- print:
format: "Service %s is %s (uptime: %s%%)"
values: ["{{{service}}}", "{{{status}}}", "{{{uptime}}}"]
field: status_message

formats service status:

{
"service": "authentication",
"status": "operational",
"uptime": 99.97,
"status_message": "Service authentication is operational (uptime: 99.97%)"
}

Error Handling with Missing Fields

Handling missing fields gracefully...

{
"event": "user_action",
"user": "bob"
}
- print:
format: "Event: %s, User: %s, Details: %s"
values: ["{{{event}}}", "{{{user}}}", "{{{details}}}"]
field: event_summary
ignore_missing: true

uses empty string for missing field:

{
"event": "user_action",
"user": "bob",
"event_summary": "Event: user_action, User: bob, Details: "
}

URL Construction

Building URLs from component parts...

{
"protocol": "https",
"hostname": "api.example.com",
"path": "/v1/users",
"user_id": "12345"
}
- print:
format: "%s://%s%s/%s"
values: ["{{{protocol}}}", "{{{hostname}}}", "{{{path}}}", "{{{user_id}}}"]
field: full_url

constructs complete URL:

{
"protocol": "https",
"hostname": "api.example.com",
"path": "/v1/users",
"user_id": "12345",
"full_url": "https://api.example.com/v1/users/12345"
}