Skip to content

Conversation

@leodido
Copy link
Owner

@leodido leodido commented Oct 5, 2025

Summary

This PR restores backward compatibility with v4.2.0 by re-adding support for the syslog.WithBestEffort() API, while preserving all improvements introduced in PR #23 (syslog.WithMachineOptions()).

Problem

PR #23 introduced breaking changes by:

  • Removing BestEfforter from the Parser interface
  • Removing the syslog.WithBestEffort() generic option
  • Requiring users to migrate to syslog.WithMachineOptions(rfc5424.WithBestEffort())

While this is a useful pattern in some scenarios, it would have forced a major version bump to v5.0.0 and broken existing user code.

Solution

Support both APIs simultaneously by:

  1. Re-adding BestEfforter to the Parser interface
  2. Restoring the syslog.WithBestEffort() generic option
  3. Converting the legacy bestEffort flag to a MachineOption internally
  4. Allowing both approaches to coexist without conflicts

How It Works

The old bestEffort bool flag is maintained for backward compatibility. When set via the old API, it's automatically converted to the appropriate MachineOption during parser construction:

// If bestEffort flag was set via old API, add it to internalOpts
if p.bestEffort {
    p.internalOpts = append(p.internalOpts, rfc5424.WithBestEffort())
}

This means both APIs produce identical behavior:

Old API (backward compatible):

parser := nontransparent.NewParser(syslog.WithBestEffort())

New API (from PR #23):

parser := nontransparent.NewParser(
    syslog.WithMachineOptions(rfc5424.WithBestEffort())
)

Mixed (also works):

parser := nontransparent.NewParser(
    syslog.WithBestEffort(),
    syslog.WithMachineOptions(rfc3164.WithYear(rfc3164.CurrentYear{}))
)

Benefits

Changes

  • syslog.go - Re-added BestEfforter to Parser interface
  • options.go - Restored WithBestEffort() generic option
  • nontransparent/parser.go.rl - Added backward compatibility logic
  • nontransparent/parser.go - Regenerated from ragel source
  • octetcounting/parser.go - Added backward compatibility logic
  • *_test.go - Added comprehensive tests for both APIs

Testing

All existing tests pass, plus new tests verify:

  • Old API works correctly
  • New API works correctly
  • Both APIs produce identical results
  • Mixed usage works correctly

Signed-off-by: Leonardo Di Donato <120051+leodido@users.noreply.github.com>
Signed-off-by: Leonardo Di Donato <120051+leodido@users.noreply.github.com>
…ons APIs

Signed-off-by: Leonardo Di Donato <120051+leodido@users.noreply.github.com>
…ns APIs

Signed-off-by: Leonardo Di Donato <120051+leodido@users.noreply.github.com>
@leodido leodido self-assigned this Oct 5, 2025
@leodido leodido marked this pull request as ready for review October 5, 2025 23:54
…orks

Signed-off-by: Leonardo Di Donato <120051+leodido@users.noreply.github.com>
…BestEffort()

Signed-off-by: Leonardo Di Donato <120051+leodido@users.noreply.github.com>
Signed-off-by: Leonardo Di Donato <120051+leodido@users.noreply.github.com>
@leodido leodido merged commit 5695cab into develop Oct 6, 2025
9 checks passed
@leodido leodido deleted the feat/reinstante-best-effort branch October 6, 2025 00:05
@leodido leodido added the enhancement New feature or request label Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants