Can Tomcat’s AccessLogValve use a per‑host time zone?
0 reputation · 18 Oct 2025, 06:17 UTC
0 reputation · 18 Oct 2025, 06:17 UTC
In a multi‑region deployment we want each host’s access log to record timestamps in the local zone of that host, rather than inheriting the JVM default. This would simplify correlation of logs across data centers and avoid the need to adjust for daylight‑saving changes on a per‑host basis.
The AccessLogValve in Tomcat 9 and 10 renders timestamps using java.util.Date in the JVM’s default time zone. The server.xml configuration offers no timezone attribute or equivalent for the valve. Changing -Duser.timezone affects the entire container and all applications, not just logging.
There is no documented per‑host or per‑context time‑zone setting for the valve, and no open issue indicates that such a feature will be added in upcoming releases. If it were introduced, would it override the JVM default only for the valve, or would it also affect other time‑dependent components?
user.timezone?35275 reputation · 18 Oct 2025, 17:02 UTC
No, Apache Tomcat's AccessLogValve does not provide a mechanism to configure a time zone independently of the JVM default. There is no timezone attribute in server.xml for the valve, and there are no documented plans to introduce per-host or per-context time zone settings for this component.
The AccessLogValve generates timestamps based on the current system time provided by the JVM. Because the valve operates as a container-level component, it relies on java.util.Date and the JVM's default time zone settings. It does not maintain its own internal calendar or time zone context.
Since the valve lacks a local configuration, the only way to change the logged time zone is via the -Duser.timezone JVM system property. However, this is a global setting. If you change this to match a host's local time, it will affect every other component within that JVM process, including:
Expires attribute of cookies may be calculated using the modified zone.new Date() or Calendar.getInstance() without specifying a time zone will inherit the user.timezone value.To achieve per-host time zone logging without risking application-level side effects, consider these two approaches:
If the host is dedicated to a single region and the application is designed to be time-zone agnostic (e.g., using UTC internally), set the JVM property in setenv.sh or setenv.bat for that specific instance:
CATALINA_OPTS="-Duser.timezone=America/New_York"
The most stable architecture for multi-region deployments is to keep all Tomcat instances on UTC and handle the time zone conversion at the ingestion or visualization layer (e.g., ELK Stack, Splunk, or Grafana). This ensures that correlation across data centers remains consistent while allowing local operators to view logs in their own time zone.
To verify the current time zone being used by your AccessLogValve, you can run the following command on a running instance to check the system property:
jcmd <pid> VM.system_properties | grep user.timezone
Diagnostic Detail Needed: Does your application logic rely on the JVM default time zone for business calculations, or is it fully UTC-compliant? If the application is not UTC-compliant, the -Duser.timezone method is not recommended.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.