Skip to content

Formatting Plain Text Logs ​

Regex with named capturing groups ​

To filter non JSON Log Lines for certain parts you have to use a regex pattern with named capturing groups.
Lets take (?P<group_name>...) as an example. P<group_name> assigns the name group_name to the group. The part inside the parentheses (...) is the pattern to match.
Then you can insert the {group_name} into your custom message template.

Example Log Line from audiobookshelf:

txt
[2025-05-03 10:16:53.154] INFO: [SocketAuthority] Socket VKrcSNa--FjwAqmSAAAU disconnected from client "example user" after 11696ms (Reason: transport close)

Regex & Template:

yaml
containers:
  audiobookshelf:
    keywords:
      - regex: '(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}).*Socket.*disconnected from client "(?P<user>[A-Za-z\s]+)"'
        template: '\nšŸ”Ž The user {user} was seen!\nšŸ• {timestamp}'
        hide_regex_in_title: true  # Hide regex in notification title for a cleaner look

Result:

Normal notification and notification with template and hide_regex_in_title:

Template Comparison

TIP

You can add the key original_log_line to your template to add the full log entry to your notification message.