[PR #5609] [MERGED] [client] Fix duplicate log lines in containers #26256

Closed
opened 2026-08-05 07:07:05 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5609
Author: @lixmal
Created: 3/17/2026
Status: Merged
Merged: 3/19/2026
Merged by: @lixmal

Base: mainHead: fix/duplicate-log-lines


📝 Commits (1)

  • 4d6f7f7 Fix duplicate log lines in containers

📊 Changes

2 files changed (+7 additions, -1 deletions)

View changed files

📝 client/cmd/service_controller.go (+1 -1)
📝 util/log.go (+6 -0)

📄 Description

Describe your changes

After #5425 added PersistentPreRunE with SetFlagsFromEnvVars(cmd.Root()) to rootCmd, the setupServiceControlCommand function was still calling SetFlagsFromEnvVars(rootCmd) a second time. Because pflag's StringSlice.Set() appends after the first call (changed flag), this doubled logFiles entries. With NB_LOG_FILE=console,/path/to/file, InitLogger created io.MultiWriter(os.Stderr, lumberjack, os.Stderr, lumberjack), writing every log line to stderr twice.

Fix: remove the redundant SetFlagsFromEnvVars(rootCmd) call and add dedup in InitLogger as defense in depth.

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Bug fix for duplicate log output, no user-facing behavior change.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed duplicate log path processing in the logging initialization system.
    • Updated environment variable initialization flow for command configuration management.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/5609 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 3/17/2026 **Status:** ✅ Merged **Merged:** 3/19/2026 **Merged by:** [@lixmal](https://github.com/lixmal) **Base:** `main` ← **Head:** `fix/duplicate-log-lines` --- ### 📝 Commits (1) - [`4d6f7f7`](https://github.com/netbirdio/netbird/commit/4d6f7f7d888b1b59add16f22eae37884d3df336a) Fix duplicate log lines in containers ### 📊 Changes **2 files changed** (+7 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `client/cmd/service_controller.go` (+1 -1) 📝 `util/log.go` (+6 -0) </details> ### 📄 Description ## Describe your changes After #5425 added `PersistentPreRunE` with `SetFlagsFromEnvVars(cmd.Root())` to `rootCmd`, the `setupServiceControlCommand` function was still calling `SetFlagsFromEnvVars(rootCmd)` a second time. Because pflag's `StringSlice.Set()` appends after the first call (`changed` flag), this doubled `logFiles` entries. With `NB_LOG_FILE=console,/path/to/file`, `InitLogger` created `io.MultiWriter(os.Stderr, lumberjack, os.Stderr, lumberjack)`, writing every log line to stderr twice. Fix: remove the redundant `SetFlagsFromEnvVars(rootCmd)` call and add dedup in `InitLogger` as defense in depth. ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) Bug fix for duplicate log output, no user-facing behavior change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed duplicate log path processing in the logging initialization system. * Updated environment variable initialization flow for command configuration management. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 07:07:05 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#26256