-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging improvements #1500
Logging improvements #1500
Conversation
Any feedback here? I hope this isn't controversial. |
pub disable_log_color: bool, | ||
|
||
/// Use UTC time in log output. | ||
#[arg(long)] | ||
pub use_utc_log_time: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I'd probably prefer to have this take a parameter, e.g. --timestamp-format=$format
where $format can be local
(default) or iso8601
(since what you've done is not just to force UTC timestamps - you've changed the format of the timestamp to be like iso8601). It's also more forward compatible if we'd want to add other formats, or make the timestamp format fully configurable with an strftime
-like string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that, but ISO 8601 is not just UTC, so I it seems like there should still be a distinction between UTC and non-UTC in logs if you really want to have local time there (I suspect that is current expectation from Substrate users that would be undesirable to change).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well then, it could be iso8601-utc
I guess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I read about ISO 8601, what a mess... There are so many way to compose valid ISO 8601 date and time that it is hardly helpful to name an option like that. Technically both local and UTC time in PR description are valid RFC 3339 formats, so the only difference between them is local vs UTC time and T
vs
between date and time (both valid).
What about something like this?:
--timestamp-format=default
--timestamp-format=tracing-subscriber
default
is the current default of Substrate, tracing-subscriber
is format used in that crate. Standard doesn't say anything about number of digits for fractional seconds, so both 3 and 6 is valid according to RFC 3339.
Here is helpful visualization: https://ijmacd.github.io/rfc3339-iso8601/
@@ -76,7 +87,8 @@ thread_local! { | |||
} | |||
|
|||
impl FormatTime for FastLocalTime { | |||
fn format_time(&self, w: &mut dyn Write) -> std::fmt::Result { | |||
fn format_time(&self, w: &mut dyn Write) -> fmt::Result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rewrite this so that:
- There are two timestamp caches, one for local time and another for UTC. (This will make
CachedTimestamp::last_utc
unnecessary.) - The body of this function would essentially be something like this:
// Outside:
fn format_time_local(...) { ... }
fn format_time_utc(...) { ... }
// ...
// Inside::
let unix_time = ...;
if self.utc {
format_time_utc(...)
} else {
format_time_local(...)
}
This way there will only be a single toplevel if self.utc
check.
if cache.last_fractional != fractional { | ||
cache.last_fractional = fractional; | ||
cache.buffer.length = TIMESTAMP_PARTIAL_UTC_LENGTH + 1; | ||
write!(&mut cache.buffer, "{:06}Z", fractional)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6 digits for the fractional part seems somewhat excessive; why not use 3 like in the non-UTC case?
The logger's asynchronous anyway so this much precision is practically useless. It'll just take extra space in the logs for no real benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is to make it identical to what tracing-subscriber
does by default. We use Substrate as a library in a bigger application, so having various logging formats interleaved is awkward and undesirable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that's reasonable if that's the tracing-subscriber
default.
if cache.timezone_offset.length == 0 { | ||
write!(&mut cache.timezone_offset, "{}", ts.offset())?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory the current timezone can change, so this should not assume that the timezone stays constant.
This is only done once per second, so its fine to do this unconditionally.
if self.utc { | ||
w.write_str(slice)?; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The with_fractional
should not be silently ignored when using UTC timestamps.
Either we make it obey with_fractional
, or the timestamp format should be an enum (so then in the UTC case there just wouldn't be with_fractional
)
@koute I'd really like to find the design which works for everyone and upstream it. Do you have any fresh thoughts on how to approach this? |
Closing as I no longer have interest in driving this forward, our chain is switching away from Substrate's runner and as such we can use normal |
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
* more relay processes in rialtoParachain<>Millau bridge * fix dashboards * fix dump-logs
This PR is an improved version of paritytech/substrate#14760
Here I changed default timestamp format in logging to include timezone offset (as requested by @koute) and added CLI option to print timestamps in UTC using the same format as the default in
tracing-subscriber
.Before:
After:
UTC:
I also did benchmarks and found that these changes introduce ~10% performance hit for local time, while UTC performance is about the same as local time was before these changes.
Before:
After:
There are also some changes to colors:
NO_COLOR
, though better approach might be to remove --disable-log-color altogether and use supports-color that automatically takes this environment variable into account (see fmt subscriber should honor NO_COLOR by default tokio-rs/tracing#2388 and Uses ANSI escape codes in dumb terminal in Sublime Text tokio-rs/tracing#2214).I recommend reviewing individual commits rather than final diff for convenience.