-
Notifications
You must be signed in to change notification settings - Fork 130
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
Timestamp support local timezone #158
Comments
For output that's expected to be consumed by a person immediately it is definitely nicer to use the local timezone. For output that's picked up by a sidecar it's not necessarily better. We could add a |
Yes, that's great. |
I'd love to have this feature - my default use case for I looked through the code, and it doesn't seem too hard to do - the main stumbling block I'm guessing is that @KodrAus - are you open to switching to I threw together a really quick proof of concept, and it looks to me as if it would work well. If this sounds good to you, I'd be happy to clean up my proof of concept and make it a PR. |
Any update on this feature? This is seems like a rather useful feature. |
If anybody else looks for this feature, its written here: https://rust-lang-nursery.github.io/rust-cookbook/development_tools/debugging/config_log.html#include-timestamp-in-log-messages:
|
hm. as an operations / SRE type, I kinda wish this was an I'm currently deploying some software where I'm using a I currently have it deployed via as much as I am a fan of "all systems should use UTC", that's often an up-stack choice and sometimes the app depends on local time. also timezones can get weirder if you support Windows too. iirc, Windows will often write the hardware clock to local timezone and disregard UTC whereas UNIX-based systems tend to write the system clock to UTC and use |
I would love for this to be integrated! FWIW, I think it would be reasonable to make this a crate feature that only pulls in chrono for the local time formatting, which would allow folks to opt-in or opt-out of the additional weight of chrono. Meanwhile, for those that want to match the default colorized style, but with local time: .format(|buf, record| {
use env_logger::fmt::Color;
use std::io::Write;
let subtle = buf
.style()
.set_color(Color::Black)
.set_intense(true)
.clone();
write!(buf, "{}", subtle.value("["))?;
write!(buf, "{} ", chrono::Local::now().format("%Y-%m-%dT%H:%M:%S"))?;
write!(buf, "{:<5}", buf.default_styled_level(record.level()))?;
if let Some(path) = record.module_path() {
write!(buf, " {}", path)?;
}
write!(buf, "{}", subtle.value("]"))?;
writeln!(buf, " {}", record.args())
}) |
For those of us in the future where the previous comment doesn't work, here's a version that uses the new included .format(|buf, record| {
use std::io::Write;
use chrono::Local;
use env_logger::fmt::style::{Style, AnsiColor};
let subtle = Style::new()
.fg_color(Some(AnsiColor::BrightBlack.into()));
let level_style = buf.default_level_style(record.level());
writeln!(buf,
"{subtle}[{subtle:#}{} {level_style}{:<5}{level_style:#}{subtle}]{subtle:#} {}",
Local::now().format("%Y-%m-%d %H:%M:%S%Z"),
record.level(),
record.args()
)
}) |
Printing timestamp in local timezone is more useful than UTC.
The text was updated successfully, but these errors were encountered: