From: Eric Wong Date: Sat, 14 Jun 2025 09:26:35 +0000 (+0000) Subject: daemon: introduce register_log public API X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1feb89a1bb395b7586d45354f950b72a70073007;p=thirdparty%2Fpublic-inbox.git daemon: introduce register_log public API Having this public API would make it easier to configure AccessLog and AccessLog::Timed middleware in multiple areas while allowing SIGUSR1 to reopen them: my $log_pfx = $ENV{LOGGER_PFX} // '/var/log/xyz/'; my $access_log = sub { my ($pfx) = @_; my $fh = PublicInbox::Daemon::register_log $log_pfx.$pfx.'.access.log'; enable 'AccessLog::Timed', logger => sub { syswrite $fh, $_[0] }; }; builder { mount 'http://foo.example.com/' => builder { $access_log->('foo'); $foo_app; }; mount 'http://bar.example.com/' => builder { $access_log->('bar'); $bar_app; }; } I'm not particularly happy about introducing a public-inbox-specific API for .psgi file writers; I can't think of another portable and reliable way to reopen all log files used by a PSGI application upon SIGUSR1. --- diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index c52ac0a11..66a25879e 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -439,6 +439,12 @@ sub reopen_logs { kill('USR1', $PublicInbox::Search::XHC->{io}->attached_pid); } +# public API: +sub register_log ($) { + my ($path) = @_; + $logs{$path} //= open_log_path(my $fh, $path); +} + sub sockname ($) { my ($s) = @_; my $addr = getsockname($s) or return;