Ghost
Ghost copied to clipboard
Ghost log timestamps are always in UTC regardless of system timezone
Issue Summary
A typical Ghost use case is to configure the logging transports to stdout or file. These transports lack automatic timestamp conversion based on the operator's timezone. Even in this case, it would be nice to be able to view the logs in local time instead of UTC without the bunyan CLI. (e.g., use journalctl, tail, grep)
Share my workaround:
Changed @tryghost/logger's GhostLogger to use timestamps based on the system timezone.
diff --git a/packages/logging/lib/GhostLogger.js b/packages/logging/lib/GhostLogger.js
index b794a1c..315efdf 100644
--- a/packages/logging/lib/GhostLogger.js
+++ b/packages/logging/lib/GhostLogger.js
@@ -497,6 +497,11 @@ class GhostLogger {
}
});
+ // Force using zoned datetime instead of UTC datetime
+ let currentDate = new Date();
+ currentDate.setMinutes(currentDate.getMinutes() - currentDate.getTimezoneOffset());
+ modifiedObject["time"] = currentDate.toISOString();
+
if (!isEmpty(modifiedObject)) {
if (modifiedObject.err) {
modifiedMessages.push(modifiedObject.err.message);
Related Issues:
- https://github.com/TryGhost/Ghost/issues/7116
- https://github.com/trentm/node-bunyan/issues/103
Steps to Reproduce
- Boot Ghost.
- A startup messages are logged with UTC timestamps, regardless of system timezone.
Note: Alpine based images have no zoneinfo and ignore the TZ environment variable, so you should use Debian based images.
Ghost Version
5.7.0
Node.js Version
v16.16.0
How did you install Ghost?
Docker official Ghost image on Ubuntu Server 22.04 LTS
Database type
MySQL 8
Browser & OS version
No response
Relevant log / error output
[2022-08-06 15:54:21] INFO Ghost is running in production...
[2022-08-06 15:54:21] INFO Your site is now available on https://[[masked]]/
[2022-08-06 15:54:21] INFO Ctrl+C to shut down
[2022-08-06 15:54:21] INFO Ghost server started in 0.265s
[2022-08-06 15:54:21] INFO Database is in a ready state.
[2022-08-06 15:54:21] INFO Ghost database ready in 0.367s
[2022-08-06 15:54:22] WARN Theme translations file locales/ja.json not found.
[2022-08-06 15:54:22] WARN Theme translations falling back to locales/en.json.
[2022-08-06 15:54:22] INFO Ghost booted in 1.146s
[2022-08-06 15:54:22] INFO Adding offloaded job to the queue
[2022-08-06 15:54:22] INFO Scheduling job update-check at 43 11 21 * * *. Next run on: Sun Aug 07 2022 21:11:43 GMT+0900 (Japan Standard Time)
[2022-08-06 15:54:22] INFO Ghost URL Service Ready in 1.43s
Code of Conduct
- [X] I agree to be friendly and polite to people in this repository
Hey there, thank you so much for the detailed bug report.
That does look like something that shouldn't happen! A PR to fix this issue would be very welcome 🙂
PR submitted in https://github.com/TryGhost/framework/pull/76.