The open_logs phase happens just before the post_config phase.
Handlers registered by PerlOpenLogsHandler are usually used for opening module-specific log files (e.g., httpd core and mod_ssl open their log files during this phase).
At this stage the STDERRstream is not yet redirected to error_log, and therefore any messages to that stream will be printed to the console from which the server is starting (if one exists).
The PerlOpenLogsHandler directive may appear in the main configuration files and within <VirtualHost>sections.
Apache will continue executing all handlers registered for this phase until the first handler returns something other than Apache::OK or Apache::DECLINED.
As we saw in the Book::StartupLog::open_logs handler, the open_logs phase handlers accept four arguments: the configuration pool,[60] the logging streams pool, the temporary pool, and the server object:
[60]Pools are used by Apache for memory-handling functions. You can make use of them from the Perl space, too.
sub open_logs { my($conf_pool, $log_pool, $temp_pool, $s) = @_; my $log_path = Apache::server_root_relative($conf_pool, $log_file); $s->warn("opening the log file: $log_path"); open $log_fh, ">>$log_path" or die "can't open $log_path: $!"; my $oldfh = select($log_fh); $| = 1; select($oldfh); say("process $$ is born to reproduce"); return Apache::OK; }
In our example the handler uses the Apache::server_root_relative( ) function to set the full path to the log file, which is then opened for appending and set to unbuffered mode. Finally, it logs the fact that it's running in the parent process.
As you've seen in this example, this handler is configured by adding the following to httpd.conf:
PerlOpenLogsHandler Book::StartupLog::open_logs
 
Continue to: