Skip to content

[mod_logfile] Add structured channel log tags#3077

Open
BIT-ja wants to merge 2 commits into
signalwire:masterfrom
BIT-ja:feature/mod-logfile-structured-tags
Open

[mod_logfile] Add structured channel log tags#3077
BIT-ja wants to merge 2 commits into
signalwire:masterfrom
BIT-ja:feature/mod-logfile-structured-tags

Conversation

@BIT-ja

@BIT-ja BIT-ja commented Jul 14, 2026

Copy link
Copy Markdown

Description

Adds structured per-channel context to mod_logfile output and a set_log_tag dialplan application.

set_log_tag name=value sets or replaces a channel log tag. set_log_tag name= and set_log_tag name remove it. mod_logfile can include captured tags and configured live channel variables in the prefix of each physical log line.

The implementation also handles APR short writes, partial-error writes, transient reopen failures, HUP/rotation cleanup, allocation failures with raw fallback, and UTF-8-safe value sanitation.

Existing UUID behavior remains enabled by default. log-tags and channel-vars are opt-in.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Code cleanup / refactor

Related Issues

None.

Testing

Validated in a Linux amd64 ASAN container:

  • make -j10

  • switch_log: 4/4

  • test_mod_logfile_prefix: 18/18

  • test_mod_logfile: 2/2

  • XML parsing and git diff --check

  • Added/updated unit tests

  • Tested manually

  • Tested with live SignalWire credentials (if applicable)

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the project's style guidelines
  • I have added tests for my changes (if applicable)
  • I have updated documentation (if applicable)
  • All existing tests pass

Additional Notes

Example profile settings:

<param name="uuid" value="true"/>
<param name="log-tags" value="true"/>
<param name="channel-vars" value="sip_call_id=callid,caller_id_number"/>

Changes:
- Use single-evaluation assertions for event creation, channel tag access, and prefix configuration helpers.
- Remove the ineffective event-reclaim teardown workaround.

Bug Analysis:
- Symptom: ASAN reported leaked events allocated by switch_event_create_plain() and switch_channel_get_log_tags().
- Root cause: fst_check_int_equals evaluates its first argument twice, so side-effecting calls allocated or duplicated an event twice and overwrote the first pointer.
- Evidence: every leak stack points to a side-effecting call passed as the first argument; the teardown workaround left the leak count and stacks unchanged.
- Fix: use fst_check(call() == expected), which evaluates the call once.
- Risk: test-only assertion changes; production behavior is unchanged.

Checkout Source: upstream/master

Verification:
- git diff --check passed.
- GitHub ASAN CI reproduced the RED state and confirmed the teardown workaround was ineffective.
- Green GitHub CI pending after push.

Committer: Codex (GPT-5)
@BIT-ja
BIT-ja force-pushed the feature/mod-logfile-structured-tags branch from e5a6039 to 7455171 Compare July 14, 2026 11:33
@timando

timando commented Jul 21, 2026

Copy link
Copy Markdown

I already made my own module to set log tags but it behaves a bit differently. set_log_tag name is equivalent to set_log_tag name=${name} instead of deleting the log tag. Also, I would expect set_log_tag name=_undef_ to unset the log tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants