Thanks to visit codestin.com
Credit goes to github.com

Skip to content

main: Use UTC in wallclock time log - #8193

Merged
likebreath merged 1 commit into
cloud-hypervisor:mainfrom
arctic-alpaca:timezone
May 14, 2026
Merged

likebreath merged 1 commit into
cloud-hypervisor:mainfrom
arctic-alpaca:timezone

Conversation

@arctic-alpaca

Copy link
Copy Markdown
Contributor

Using jiff::Timestamp::now() instead of jiff::Zoned::now() skips the timezone logic required for Zoned. This makes the timestamp UTC, with the appropriate Z suffix.

Alternatively, we could use the default formatting without strftime(...), but that includes three more digits of the fractional seconds, which I don't think are necessary.

println!("{}",jiff::Timestamp::now().strftime("%Y-%m-%dT%H:%M:%S%.6fZ"));
// 2026-05-12T09:29:29.622730Z
println!("{}",jiff::Timestamp::now());
// 2026-05-12T09:29:29.622739847Z

@phip1611 phip1611 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Having UTC rather than unspecified local time is definitely an improvement!

I'm in favor of also adding Token::WallClockTz (or chose a different name) to give users more freedom. This requires jiffs tz-system feature

Comment thread cloud-hypervisor/src/logger.rs Outdated
write!(
out,
"{}",
jiff::Timestamp::now().strftime("%Y-%m-%dT%H:%M:%S%.6fZ")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jiff::Timestamp::now().strftime("%Y-%m-%dT%H:%M:%S%.6fZ")
jiff::Timestamp::now()

I tested this locally and it prints like this:

Without strftime: 2026-05-12T09:34:52.3328526Z
With    strftime! 2026-05-12T09:34:52.332873Z

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I've just noticed you mentioned that in your PR. No strong opinion!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less code is better - lets's just go without strftime

"{}",
jiff::Zoned::now().strftime("%Y-%m-%dT%H:%M:%S%.6f")
),
Token::WallClock => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if we add Token::WallClockTz that prints jiff::Zoned::now()? Then we do not need to discuss what's "the right thing to do" and give users the necessary freedom

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would require us dealing with what to do when jiff cannot detect the timezone. I would prefer to keep this simple until we need more complexity.

@phip1611 phip1611 May 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a hypothetical problem or can you reproduce a failure? When could this happen? If a system can't obtain the timezone, then a user simply should not configure {wallclock_local} into the log format? Am I missing something?

I don't have a strong opinion but I guess some people prefer local time with timezone information in their logs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess some people prefer local time with timezone information in their logs

I would not implement features we cannot remove without a breaking change to the CLI without a concrete need for it.

Is this a hypothetical problem or can you reproduce a failure? When could this happen? If a system can't obtain the timezone, then a user simply should not configure {wallclock_local} into the log format? Am I missing something?

It's a possible code path, so we should handle it without putting the burden on the user, which might not even be aware, that their system is configured in a way that breaks the timezone detection. Whether this is likely to happen and under which circumstances, I'm not sure.

This is what jiff's docs say:

If the system’s default time zone could not be determined, or if the tz-system crate feature is not enabled, then this returns TimeZone::unknown. A WARN level log will also be emitted with a message explaining why time zone detection failed. The fallback to an unknown time zone is a practical trade-off, is what most other systems tend to do and is also recommended by relevant standards such as freedesktop.org.

An unknown time zone behaves like TimeZone::UTC, but will print as Etc/Unknown when converting a Zoned to a string.

If you would like to fall back to UTC instead of the special “unknown” time zone, then you can do TimeZone::try_system().unwrap_or(TimeZone::UTC).

Falling back to UTC is most likely the better approach as I don't think we want an IANA-style identifier in the logs as that would create a lot of noise.

If Token::WallClockTz is not required to land this PR, I would prefer to keep it separate.

@phip1611 phip1611 May 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! We can add it in future if needed - no need to slow down this PR

"{}",
jiff::Zoned::now().strftime("%Y-%m-%dT%H:%M:%S%.6f")
),
Token::WallClock => {

@phip1611 phip1611 May 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While on it, do you think it would make sense to add documentation to Token::WallClock saying:

Wallclock using ISO 8601 / RFC 3339-style.?

WDYT? We missed this in the original PR

@arctic-alpaca
arctic-alpaca marked this pull request as ready for review May 12, 2026 10:22
@arctic-alpaca
arctic-alpaca requested a review from a team as a code owner May 12, 2026 10:22

@rbradford rbradford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey dokey. Lets go with UTC for now.

@rbradford
rbradford enabled auto-merge May 12, 2026 11:30
@rbradford
rbradford added this pull request to the merge queue May 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks May 12, 2026
@rbradford
rbradford added this pull request to the merge queue May 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 12, 2026
Comment thread cloud-hypervisor/src/logger.rs Outdated
let out = buf.contents();
let out = out.trim();
assert_eq!(out.len(), 26, "got: {out}");
assert_eq!(out.len(), 30, "got: {out}");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit test is failing:

thread 'logger::tests::logger_wallclock_is_rfc3339' panicked at cloud-hypervisor/src/logger.rs:370:9:
assertion `left == right` failed: got: 2026-05-12T15:59:00.66858127Z
  left: 29
 right: 30
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    logger::tests::logger_wallclock_is_rfc3339

test result: FAILED. 34 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass `-p cloud-hypervisor --bin cloud-hypervisor`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware that jiff uses the minimum required precision to render the value. I fixed the precision to match the behavior from before.

Using `jiff::Timestamp::now()` instead of `jiff::Zoned::now()` skips the
timezone logic required for `Zoned`. This makes the timestamp UTC, with
the appropriate `Z` suffix.

On-behalf-of: SAP [email protected]
Signed-off-by: Julian Schindel <[email protected]>
@likebreath
likebreath added this pull request to the merge queue May 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 13, 2026
@likebreath
likebreath added this pull request to the merge queue May 13, 2026
Merged via the queue into cloud-hypervisor:main with commit 466d949 May 14, 2026
41 checks passed
@arctic-alpaca
arctic-alpaca deleted the timezone branch July 24, 2026 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants