Skip to content

add option to send debug logs to a unix socket#48300

Merged
jkarneges merged 2 commits intomainfrom
jkarneges/debug-socket
Feb 13, 2026
Merged

add option to send debug logs to a unix socket#48300
jkarneges merged 2 commits intomainfrom
jkarneges/debug-socket

Conversation

@jkarneges
Copy link
Member

@jkarneges jkarneges commented Feb 4, 2026

This adds an option to connmgr for sending debug logs to a unix socket. The --debug-socket arg can be used to specify a unix socket path to serve logs from. Any clients connected to that path receive all logs regardless of the configured log level limit.

The debug logger is invoked from the global logger so that all logs can be sent through it. However, the debug logger also implements the Log trait, in case we ever want to log to it explicitly.

To ensure the mechanism doesn't introduce too much overhead when it is unused, the Log::enabled trait method skips logging when no clients are connected. This means expensive logging code guarded by log_enabled! should get skipped appropriately.

Broadcasting to clients is done from a separate thread to avoid tying up callers. When a logging call is made, the logger simply sends the log message to a channel and returns. A separate thread then reads from the channel, handling the rest of the pipeline. The channel is bounded and the send is best-effort using non-blocking try_send() calls, so if the channel is full then logs are dropped.

@jkarneges jkarneges changed the title debug socket wip add option to send debug logs to a unix socket Feb 10, 2026
@jkarneges jkarneges force-pushed the jkarneges/debug-socket branch 2 times, most recently from 65a3fe2 to d5b6ea1 Compare February 11, 2026 16:32
@jkarneges jkarneges marked this pull request as ready for review February 11, 2026 16:33
@jkarneges jkarneges requested a review from a team February 11, 2026 16:42
src/core/log.rs Outdated
// Send immediately if the client's queue isn't full, else drop
match c.sender.try_send(Rc::clone(&msg)) {
Err(mpsc::TrySendError::Disconnected(_)) => false,
_ => true, // Success or full
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe push a log to systemd to know if the queue is full?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since drops can only happen when there is at least one debug log connection open, I came up with a way to log this information to the debug clients rather than the main logs. Basically there's a drop counter for the main queue and one for each client, and they stack.

src/core/log.rs Outdated
LOGGER.get().expect("logger should be initialized")
}

const QUEUE_MAX: usize = 1000;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we ever want to tune this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. For I've now made it dynamic based on the number of worker threads. We can tweak this depending on how things go.

src/core/log.rs Outdated
fn send(&self, message: String) {
if let Some(sender) = &self.msgs {
// Send immediately if the queue isn't full, else drop
let _ = sender.try_send(LogMessage { inner: message });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

systemd log to know we're hitting full queues?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

return;
}

let now = OffsetDateTime::now_utc().to_offset(local_offset().unwrap_or(UtcOffset::UTC));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose default to logging in UTC offset with maybe a flag for local timezone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is the same as our global logger which I think is the right way to go. Local time is less surprising behavior out-of-the-box. Folks that want UTC (e.g. on server nodes) can configure timezones accordingly.

@jkarneges jkarneges force-pushed the jkarneges/debug-socket branch from 07bef01 to 060271a Compare February 13, 2026 00:02
@jkarneges jkarneges merged commit 9d7950b into main Feb 13, 2026
19 checks passed
@jkarneges jkarneges deleted the jkarneges/debug-socket branch February 13, 2026 15:44
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