Improvement of Timezone Handling and Caddy Log Formatting
Description:
It has been possible to set container timezones via the TZ environment variable without installing tzdata. To improve visibility and usability, I have explicitly added this ENV variable to all Dockerfiles and updated the documentation.
FrankenPHP & Caddy Logging:
Currently, the FrankenPHP images (using Caddy) output logs in UTC by default, which can complicate debugging. I have adjusted the Caddy configuration to:
- Respect the timezone set via the
TZvariable in log outputs. - Introduce a new variable,
CADDY_LOG_DATETIME_FORMAT, allowing for custom timestamp formats supported by Caddy.
Backward Compatibility:
These changes are fully backward compatible. Default values are in place, ensuring that if TZ or CADDY_LOG_DATETIME_FORMAT are not set, the behavior remains exactly as it is now.
Examples
docker-compose.yml
services:
app:
image: serversideup/php:8.5-frankenphp
environment:
TZ: Europe/Berlin
CADDY_LOG_DATETIME_FORMAT: "wall"
...
Running directly in your terminal:
docker run --rm -it \
-e TZ=Europe/Berlin \
-e CADDY_LOG_DATETIME_FORMAT=wall \
serversideup/php:8.5-frankenphp
Please take a look at the following file:
https://github.com/serversideup/docker-php/blob/main/src/variations/frankenphp/etc/frankenphp/log-level/global/debug.caddyfile#L1C1-L1C6
There is on line one the word "debug". I just let it the way it was and didnt find any reference in the caddy logs for that. It could be a possible bug?
Whoops, I should have commented here 😃
Thanks for opening a PR! I will review for the next release.
Sorry for the delay. I was working on serversideup/php today but I had another bug take many hours longer than expected 🙃
I'll circle back and take a look at this soon.
@jaydrogers I made a mistake on this one.
I declared TZ to be available on all images, but that is not true 🤦♂️
You can use TZ only on debian based images. On alpine images, tzdata would have to be installed.
Let me know, how should I progress on this one.
I reverted recent changes to Dockerfiles that attempted to set the timezone via the TZ environment variable.
Reason for Revert
The TZ environment variable relies on the presence of timezone data, which is not included in Alpine based images. Consequently, this configuration does not work on images built on Alpine.
Impact & New Standard
Alpine Images:
-
Alpine-based images will continue to default to the
UTCtimezone. -
Changing the timezone on these images now explicitly requires installing the
tzdatapackage (the standard Alpine method). -
This typically requires building your own custom image based on the serversideup image and including the
tzdatainstallation step. -
Caddy logs within these Alpine images will still use
UTCtimestamps.
Debian Images:
- The
TZenvironment variable remains functional for changing the timezone on Debian-based images (which have been the default for some time). This behavior is now explicitly documented.
New Feature for Log Clarity
To improve log readability, especially for users remaining on UTC, we have introduced a new environment variable:
CADDY_LOG_DATETIME_FORMAT: Allows users to customize the timestamp format of the Caddy access logs, providing better clarity and integration with external logging tools.
How much space gets added to Alpine if we include tzdata by default?
To be honest I didnt try, because you said you didnt want any packages installed, that would possibly make the images bigger, wich is understandable.
No problem. I can take a look if needed. I appreciate your efforts on this 👍
Please also take a look at this file:
https://github.com/serversideup/docker-php/blob/main/src/variations/frankenphp/etc/frankenphp/log-level/global/debug.caddyfile#L1C1-L1C6
On the first line there is the word debug wich isnt in any other files and I couldnt find anything on the caddy documentation about it. It might be a typo.