Skip to content

[FEATURE] Send the log of a single service to a file, or turn it off, with SERVICE_*_LOG - #676

Draft
Kanti wants to merge 4 commits into
bugfix/logs-to-container-logfrom
feature/log-targets-per-service
Draft

Kanti wants to merge 4 commits into
bugfix/logs-to-container-logfrom
feature/log-targets-per-service

Conversation

@Kanti

@Kanti Kanti commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Builds on #657, whose branch is its base: it uses the split of syslog by level and the fallback for files that cannot be written from there.

Why

The review of #657 asked where logs should go if not all into the container log. The container log stays the way the images are meant to be used. LOG_STDOUT and LOG_STDERR move a whole stream of all services into one file, which #657 now advises against. This pull request adds the finer way: one log of one service to a file of its own, or off with /dev/null, for example the access logs of Nginx and PHP-FPM, which are the loudest. The image does not rotate these files, on purpose: files are not the way the images propagate.

What

  • New variables, not set by default; each changes only the lines that still point to /docker.stdout or /docker.stderr:

    Variable Log
    SERVICE_NGINX_ACCESS_LOG, SERVICE_NGINX_ERROR_LOG access_log, error_log of Nginx (virtual hosts and Nginx itself); 20-nginx.sh
    SERVICE_APACHE_ACCESS_LOG, SERVICE_APACHE_ERROR_LOG CustomLog/TransferLog, ErrorLog of Apache; 20-apache.sh
    SERVICE_PHPFPM_ACCESS_LOG access.log in zz-environment.conf, which comes after docker.conf
    SERVICE_PHPFPM_ERROR_LOG error_log in a [global] section of zz-environment.conf, slowlog, and php_admin_value[error_log] in application.conf (the first php_admin_value wins); php.error_log still wins for the errors of PHP scripts
    SERVICE_SYSLOG_LOG, SERVICE_SYSLOG_ERROR_LOG the two destinations of syslog-ng (up to warning, from err); 10-init.sh restores the configuration of the image at every start of syslog-ng and switches each target that is no pipe to file()
  • 04-log-files.sh: creates a missing file of these variables as root:root 0644, as for LOG_STDOUT and LOG_STDERR; a file that exists, such as /dev/null, keeps its owner and mode. A file that cannot be created or written drops its variable with Cannot write to <file> of <variable>: its logs stay in the container log, so the service starts and its log stays in the container log.

  • Docs: docs/environment-variables.md gets a section "Logs of the services" with the variables, /dev/null, that the container log is the way the images are meant to be used, that the image does not rotate the files, and not to turn off the error logs; LOG_STDOUT points to it. docs/customization.md, "Logs", names the variables.

  • make generate.

Tests

Each in a container of its own, in the image where the service comes first (AGENTS.md):

  • ServiceLogChecks (webdevops/php, new):
    • testServiceLogsGoToTheFilesOfTheirVariables: all four variables of PHP-FPM and syslog-ng set to files; a request with error_log() and logger at info and err. The access line, the PHP error and ready to handle connections, and the two messages are each in their file, the files are 644 root:root, and none of the lines is in the container log.
    • testServiceLogsGoNowhereWithDevNull: SERVICE_PHPFPM_ACCESS_LOG and SERVICE_SYSLOG_LOG set to /dev/null; the access line and a message at info are not in the container log, while the PHP error and a message at err are; /dev/null stays character special file 666 root:root.
    • testServiceLogStaysInTheContainerLogWhenItsFileCannotBeWritten: SERVICE_PHPFPM_ACCESS_LOG in /proc: the warning in the container log, the access line on its stdout.
  • NginxEnvironmentChecks (php-nginx): testNginxLogsToTheFilesOfItsLogVariables (a 403 and kill -9 of a worker: access line, error and alert in the two files, 644 root:root, none in the container log), testNginxAccessLogGoesNowhereWithDevNull.
  • ApacheEnvironmentChecks (php-apache): testApacheLogsToTheFilesOfItsLogVariables (a 403 with AH00132 in the two files, then /dev/null for the access log).

How it was verified

  • Image tests of php, php-nginx and php-apache, each 8.4 and 8.4-alpine, on the published images with the conf/ of this branch copied over: the new tests pass, except testNginxAccessLogGoesNowhereWithDevNull in the first run, whose check also matched the request in the error line of Nginx; fixed in the last commit, which only changes that check. The other failures come from the overlay itself (build scripts and installers copied back in) and, in Alpine, from installs through apk that the network of the test machine refuses.
  • Checks of ci/: GrumPHP passes except composer audit, which reports two advisories of symfony/expression-language published on 2026-11-25; they affect master as well.
  • Not verified: the -dev images, arm64, the other PHP versions. The CI of this pull request runs the tests on all images.

… with SERVICE_*_LOG

SERVICE_NGINX_ACCESS_LOG, SERVICE_NGINX_ERROR_LOG, SERVICE_APACHE_ACCESS_LOG, SERVICE_APACHE_ERROR_LOG,
SERVICE_PHPFPM_ACCESS_LOG, SERVICE_PHPFPM_ERROR_LOG, SERVICE_SYSLOG_LOG and SERVICE_SYSLOG_ERROR_LOG send one log
of one service to a file instead of the container log; /dev/null turns it off. Not set, the logs stay in the
container log, which remains the way the images are meant to be used. A missing file is created as root:root 0644
at the start, as for LOG_STDOUT and LOG_STDERR, and a file that exists, such as /dev/null, keeps its owner and mode.
The image does not rotate the files.
…per-service

# Conflicts:
#	ci/image-tests/Checks/SyslogChecks.php
#	docker/php/8.2-alpine/conf/provision/entrypoint.d/04-log-files.sh
#	docker/php/8.2/conf/provision/entrypoint.d/04-log-files.sh
#	docker/php/8.3-alpine/conf/provision/entrypoint.d/04-log-files.sh
#	docker/php/8.3/conf/provision/entrypoint.d/04-log-files.sh
#	docker/php/8.4-alpine/conf/provision/entrypoint.d/04-log-files.sh
#	docker/php/8.4/conf/provision/entrypoint.d/04-log-files.sh
#	docker/php/8.5-alpine/conf/provision/entrypoint.d/04-log-files.sh
#	docker/php/8.5/conf/provision/entrypoint.d/04-log-files.sh
#	docker/php/8.6-alpine/conf/provision/entrypoint.d/04-log-files.sh
#	docker/php/8.6/conf/provision/entrypoint.d/04-log-files.sh
#	docs/environment-variables.md
#	provisioning/base/general/provision/entrypoint.d/04-log-files.sh
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant