]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
daemon: introduce register_log public API
authorEric Wong <e@80x24.org>
Sat, 14 Jun 2025 09:26:35 +0000 (09:26 +0000)
committerEric Wong <e@80x24.org>
Mon, 16 Jun 2025 20:10:56 +0000 (20:10 +0000)
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.

lib/PublicInbox/Daemon.pm

index c52ac0a1137a0de10ded5e9512ceb256681b7eb1..66a25879e011af4f19db1821ed46aba5a50f6b5d 100644 (file)
@@ -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;