Skip to content

Structured logging to journald - #2969

Draft
darkexplosiveqwx wants to merge 26 commits into
pi-hole:developmentfrom
darkexplosiveqwx:log-journal
Draft

Structured logging to journald#2969
darkexplosiveqwx wants to merge 26 commits into
pi-hole:developmentfrom
darkexplosiveqwx:log-journal

Conversation

@darkexplosiveqwx

Copy link
Copy Markdown
Contributor

Thank you for your contribution to the Pi-hole Community!

Please read the comments below to help us consider your Pull Request.

We are all volunteers and completing the process outlined will help us review your commits quicker.

Please make sure you

  1. Base your code and PRs against the repositories developmental branch.
  2. Sign Off all commits as we enforce the DCO for all contributions
  3. Sign all your commits as they must have verified signatures
  4. File a pull request for any change that requires changes to our documentation at our documentation repo

What does this PR aim to accomplish?:

Discussed in #2897
Stacked on top of #2958, #2960 and #2968
Requires pi-hole/docker-base-images#175 to build.

How does this PR accomplish the above?:

Link documentation PRs if any are needed to support this PR:


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code and I have tested my changes.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)
  6. I have checked that another pull request for this purpose does not exist.
  7. I have considered, and confirmed that this submission will be valuable to others.
  8. I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  9. I give this submission freely, and claim no ownership to its content.

  • I have read the above and my PR is ready for review. Check this box to confirm

@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please resolve those before we can evaluate the pull request.

We never read from FTL.log and webserver.log after opening them, so +read is unnecessary.

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Conflicts have been resolved.

carries to: FIFO, webserver.log
changes webserver.log format (again)

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
adresses review:
- `log_web()` now takes `(priority, flag, ...)` and most call sites pass
  `DEBUG_NONE`. Since `log_web_debug()` is already a macro, a matching
  convenience macro for the plain info/error case would drop
  `DEBUG_NONE` from those call sites and read cleaner. It is only a
  handful of sites, so this is readability rather than diff size.

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
The static variable process was set by init_FTL_log() but never read
anywhere in the codebase - it was dead code since its introduction in
8f40798 (2021). Removing it also eliminates the name parameter which
is no longer needed.

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
this would be duplicated with log_web(LOG_INFO, "Initializing HTTP
server on ports \"%s\"", config.webserver.port.v.s);

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Code Review:  And FTLCONF_files_log_ftl="" is skipped by
getLogFilePathENV() but accepted by the regular load, which is a small
inconsistency.

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Comment thread src/log.c
// held, so writes to different files never contend. The reopen flag is
// per-file so SIGUSR2 only touches the fd that actually needs it.
static bool write_log_line(struct log_fd *log, const char *line, size_t len)
{
Comment thread src/log.c

void init_FTL_log(const char *name)
// Open cached log fds from config paths.
// open_log_fds(true): open FTL.log only (called early, before full config)
Code Review:

On the fallback, the direction is right but the snippet has two problems. First, the comparison is inverted: syslog priorities ascend as severity drops (LOG_CRIT 2 < LOG_ERR 3 < LOG_WARNING 4 < LOG_INFO 6), so priority >= LOG_WARNING catches WARNING/NOTICE/INFO/DEBUG and skips exactly the ERROR and CRIT lines we are trying to save. It needs to be priority <= LOG_WARNING. Second, config.files.log.webserver.v.s == NULL will practically never be true: the default is /var/log/pihole/webserver.log, initConfig() always seeds v from d, and we have no empty-means-disabled handling for that key (unlike files.pcap, which uses validate_filepath_empty). Setting files.log.webserver = "" passes validate_webserver_logfile() and then simply fails in fopen(). So the case that actually loses messages is the open failing - empty path, unwritable directory, read-only filesystem - and there we currently drop the line in daemon mode without even the syslog fallback that _FTL_log() has. Please gate on weblog == NULL instead, and rather than duplicating the formatting, just hand the already-formatted buffer over

_log_web() does not honour print_log/print_stdout outside CLI mode, so log_ctrl(false, false) (e.g., src/api/action.c:49) no longer silences everything, and it never prints to stdout in non-daemon mode - so pihole-FTL -f no longer shows the relocated errors on the console the way log_err() did. Routing through _FTL_log() as above fixes the second half for free.

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Code Review:

Two things are still open from my second point, all in src/webserver/webserver.c: the OOM sites (lines 64, 73, 82, 91, 100, 360, 506, 665, 715, 814, 836, 948) and the startup failures - 619 Not starting web server as webserver.port is empty, 652 Initializing HTTP library failed!, 658 Failed to build web paths ... and the whole mg_start2() failure block at 871-874. Those are process-health signals: "web interface will not be available" is what someone greps FTL.log for. Line 874 also became circular - we now write "Hint: Check the webserver log at ..." into the webserver log. Worth noting that a bad files.log.webserver is itself a plausible reason for that block to run, and then all four lines disappear in daemon mode, i.e., no web interface and nothing in the logs.

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
the embedded dnsmasq already does a fd cleanup on startup, so this is not strictly necessary, but still good practice

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
https://discourse.pi-hole.net/t/something-on-my-network-trying-to-contact-zoom/86982/11
is too funny, had to do it

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
TID= is specified for use in man:systemd.journal-fields(7)

Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx
<101737077+darkexplosiveqwx@users.noreply.github.com>
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please resolve those before we can evaluate the pull request.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants