Optional microsecond timestamp in the log (debug.extra) - #3005
Draft
DL6ER wants to merge 1 commit into
Draft
Conversation
The millisecond resolution of our log timestamps is too coarse to order events that happen inside the same millisecond, which is exactly what one needs when chasing down a timing problem. Instead of adding yet another config option for this, we reuse `debug.extra`, the flag that already exists for temporary investigations: when it is enabled, `get_timestr()` prints six instead of three fractional digits. ``` 2026-08-06 08:01:40.086 CEST [12345M] INFO: ... (default) 2026-08-06 08:01:40.086300 CEST [12345M] INFO: ... (debug.extra = true) ``` This covers every timestamped log line (FTL.log, webserver.log and stdout) as they all go through `get_timestr()`. The default output is unchanged. Signed-off-by: DL6ER <dl6er@dl6er.de>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances Pi-hole FTL’s log timestamp precision for debugging scenarios by switching fractional timestamp output from milliseconds to microseconds when debug.extra is enabled, while keeping the default log format unchanged.
Changes:
- Update
get_timestr()to emit 6 fractional digits (microseconds) whenconfig.debug.extrais set, otherwise preserve the existing 3-digit millisecond format. - Extend the
debug.extraconfig help text to document the timestamp-resolution change.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/log.c | Adds conditional microsecond vs millisecond fractional timestamp formatting based on debug.extra. |
| src/config/config.c | Updates debug.extra help text to mention the increased log timestamp resolution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+110
to
+113
| // debug.extra bumps the resolution to microseconds so events | ||
| // happening within the same millisecond can still be ordered | ||
| const bool micros = config.debug.extra.v.b; | ||
| const int subsec = micros ? (int)tv.tv_usec : (int)(tv.tv_usec/1000); |
yubiuser
reviewed
Aug 6, 2026
yubiuser
left a comment
Member
There was a problem hiding this comment.
test/pihole.toml needs adjustment
DL6ER
marked this pull request as draft
August 6, 2026 13:20
Member
Author
debug.extra is setdebug.extra)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this implement/fix?
Our log timestamps carry millisecond resolution. That is fine for everyday use, but too coarse whenever one is actually chasing a timing problem - a burst of related log lines regularly ends up sharing the very same millisecond, so the log no longer tells us in which order things happened.
Rather than adding yet another config option for this, we reuse
debug.extra, the flag that already exists for exactly this kind of temporary investigation ("Temporary flag that may print additional information [...] meant to be used whenever needed for temporary investigations"). When it is enabled,get_timestr()prints six instead of three fractional digits:As every timestamped log line goes through
get_timestr(), this coversFTL.log,webserver.logand the foreground/stdout output alike. The default output is bit-for-bit unchanged, so nothing that reads our logs today is affected unless the flag is deliberately turned on.The
debug.extrahelp text mentions the added resolution so the behavior is discoverable frompihole-FTL --config debug.extrainstead of only from the source.Note that the handful of lines emitted before the config has been read still use millisecond resolution - the flag simply is not known yet at that point.
How to test the change during review
/var/log/pihole/FTL.loghave three fractional digits, as before:FTLCONF_debug_extra=true./var/log/pihole/webserver.logwhile the flag is set - it uses the same time string and switches along.Automated coverage: the existing
test/suite runs withdebug.extraunset, so the log format it sees is unchanged;test_final.batscontinues to scanFTL.logfor unexpectedWARNING/ERROR/CRITlines as before.Related issue or feature (if applicable): N/A
Pull request in docs with documentation (if applicable): N/A
By submitting this pull request, I confirm the following:
git rebase)Checklist:
developmentbranch.