Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Conversation

@KrX3D
Copy link

@KrX3D KrX3D commented Apr 16, 2025

Enhanced Syslog Component with Filtering and Advanced Configuration

This PR significantly enhances the Syslog component with a comprehensive message filtering system, improved configuration options, and additional automation capabilities. The changes make the component more versatile for complex logging needs while maintaining backward compatibility.
Major Enhancements

1. Runtime Parameter Configuration

This enhancement adds the ability to modify component configuration during runtime, without requiring a device restart. The following parameters can now be changed dynamically:
Network Settings

  • Server IP address: Can be changed on-the-fly with set_server_ip() or through automations
  • Server port: Can be changed with set_server_port() or through automations

Component Behavior

  • Enable/disable status: Toggle the entire component with set_globally_enabled()
  • Logger message capture: Toggle with set_enable_logger_messages()
  • Direct logging: Toggle with set_enable_direct_logs()
  • Color stripping: Toggle with set_strip_colors()

Filtering System

  • All filter operations (add, remove, clear, set string) can be performed at runtime
  • Filter mode (include/exclude) can be changed with set_filter_mode()

2. Complete Message Filtering System

New filtering mechanism that supports both include and exclude modes:

  • filter_mode: include - Only forward logs from specified tags/components
  • filter_mode: exclude - Forward all logs except from specified tags/components

Multiple filter configuration methods:

  • Static list in YAML config: filters: [component1, component2]
  • Dynamic comma-separated string: filter_string: "component1,component2"
  • Text entity binding: filter_text: id_of_text_entity

Runtime filter management through new automation actions:

  • syslog.add_filter: Add a component/tag to filter list
  • syslog.remove_filter: Remove a component/tag from filter list
  • syslog.clear_filters: Clear all filters
  • syslog.set_filter_string: Update the filter string (parses comma-separated values)

3. Log Source Management

  • Source categorization through LogSource enum (LOGGER, DIRECT, INTERNAL)

Source-specific prefixing:

  • direct_log_prefix: Add prefix to logs from direct calls (API/automations)
  • logger_log_prefix: Add prefix to logs from the ESPHome logger system

4. Enhanced Runtime Control

Global component control:

  • globally_enabled flag to completely turn component on/off

Source-specific control:

  • enable_logger (previously existing): Enable/disable forwarding of logger messages
  • enable_direct_logs (new): Enable/disable forwarding of direct log calls

5. Networking Improvements - special thanks to dwmw2 https://github.com/dwmw2/esphome_syslog/tree/esp-ipv6-support

  • Removed external library dependency by implementing native UDP socket handling, thanks to dwmw2 who added the initial implementation of plain UDP socket connections
  • Added ESP-IDF framework support beyond just Arduino framework, based on dwmw2's work in the esp-ipv6-support branch
  • Added IPv6 support for syslog server addresses, leveraging the socket implementation provided by dwmw2
  • Enhanced compatibility with newer ESPHome versions (2024.8.0+) through updated socket initialization methods

Also included in his pull request: #17

6. Other Improvements

  • Better error handling with appropriate logging for issues
  • Enhanced diagnostics for filter changes and component operations
  • Comprehensive code documentation with detailed comments

Configuration Example

syslog:
  id: my_syslog
  ip_address: 192.168.1.100
  port: 514
  client_id: esp_device
  # Filter settings
  filter_mode: exclude  # or "include"
  filters:
    - wifi
    - api
  # Can also use filter_string: "wifi,api" instead
  # Source prefixes
  direct_log_prefix: "DIRECT"
  logger_log_prefix: "LOGGER"
  # Control flags
  enable_logger: true
  enable_direct_logs: true
  globally_enabled: true
  strip_colors: true
  min_level: INFO

Automation Examples

on_...:
  - syslog.log:
      level: 4  # INFO level
      tag: "custom_tag"
      payload: "This is a direct log message"
  
  - syslog.add_filter:
      tag: "sensor"
      
  - syslog.set_filter_string:
      filter_string: "wifi,sensor,bluetooth"

## Enhanced Component Functionality

	Added filter system with include/exclude modes
	Added support for filter strings (comma-separated list of tags)
	Added direct logging & logger message control
	Added text sensor support for filter strings
	Added prefixing capabilities for different log sources

## New Configuration Options

	Added filter_mode with include/exclude options
	Added filters and filter_string options
	Added enable_direct_logs and globally_enabled flags
	Added direct_log_prefix and logger_log_prefix options
	Added filter_text sensor integration

## New Automation Actions

	Added syslog.add_filter action
	Added syslog.remove_filter action
	Added syslog.clear_filters action
	Added syslog.set_filter_string action

## Networking Changes

	Thanks to dwmw2 who added the initial implementation of plain UDP socket connections:
		Replaced external Syslog library dependency with native UDP socket handling
		Added IPv6 support
		Added compatibility with newer ESPHome versions

## Code Structure Improvements

	Added comprehensive documentation to methods and classes
	Enhanced error handling and logging
	Added log source tracking via LogSource enum
@KrX3D KrX3D changed the title # Changelog Several config options and features added Apr 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant