Skip to content
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

Add option to add timestamps to the log output #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mankinskin
Copy link

The timestamps currently have a fixed formatting, but it should be fine for most cases and matches the default format in tracing.

It should be pretty easy to add configuration for this later on but I favored simplicity for now.

@mankinskin
Copy link
Author

Closes #10

@colelawrence
Copy link
Member

Thank you for the contribution!

We're about to take a closer look at all the feedback we've gotten so far to consider the API design for our next version.

Copy link
Member

@colelawrence colelawrence left a comment

Choose a reason for hiding this comment

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

Just a few thoughts on the choices made. Don't feel obligated to make changes since we'll follow up to address all issues and PRs as one design problem.

@@ -1,4 +1,5 @@
target/
Cargo.lock
Copy link
Member

Choose a reason for hiding this comment

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

I haven't seen this before, but just found the following resource on removing Cargo.lock

Is this change for the same rationale?
https://doc.rust-lang.org/cargo/faq.html#why-do-binaries-have-cargolock-in-version-control-but-not-libraries

Copy link
Author

Choose a reason for hiding this comment

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

I didn't know it is recommended to check in the .lock file for binaries, I never checked it in. But it works either way and in general, the Cargo.lock is not checked in. But apparently it can be used to determine the exact dependencies a build was compiled with.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually if you don't check in the Cargo.lock for a binary, the build will in general not be repeatable, because the versions of dependencies could have been updated. If you have a dependency with dependency = "x.y.z" in your Cargo.toml, cargo will take any version that has the same major number x.y and at least z minor version. You will need to specify "=x.y.z to get the exact version, however this is rarely done.

@@ -23,3 +23,4 @@ crate-type = ["cdylib", "rlib"]
tracing = {version = "0.1", features = ["attributes"]}
tracing-subscriber = {version = "0.2", features = ["registry"]}
wasm-bindgen = {version = "0.2"}
chrono = { version = "^0.4", features = ["wasmbind"] }
Copy link
Member

Choose a reason for hiding this comment

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

I've seen chrono often put behind a feature flag. Is that possibly to allow avoiding extra dependencies?

We might consider adding a feature-flag like that here as a follow-up to this PR.

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure about that, chrono was once incompatible with wasm, which had already caused me issues, but is fixed now apparently. It may probably still be useful to have a feature flag for time logging.

Copy link
Contributor

Choose a reason for hiding this comment

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

Being able to avoid extra dependencies is always a good thing, potentially leading to shorter compile times and less network bandwidth used for the build. On the other hand, every feature carries a complexity cost, and unfortunately features aren't that discoverable yet. As chrono is fairly small and very compatible (depending on features, it can even be no_std), I don't think we'll need to put it behind a feature. I don't understand the usage sufficiently to gauge if we should at least make wasmbind a default feature otherwise.

src/lib.rs Outdated
Comment on lines 298 to 330
let timestamp = if self.config.log_time {
chrono::Local::now().format("%a %d %T%.f").to_string()
} else {
String::new()
};
Copy link
Member

Choose a reason for hiding this comment

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

If we're in certain WASM contexts where Date is available, I wonder if we could just leverage (new Date()).toSomeFormatString(). This may allow us to drop chrono entirely.

Just thinking out loud.

@llogiq might have other ideas.

Copy link
Author

@mankinskin mankinskin Oct 1, 2020

Choose a reason for hiding this comment

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

there is js_sys which exposes the Date API. Although I think it is not very future proof, as most Rust crates use std::time or chrono. I think js_sys is even used internally by chrono to get the time in wasm.

Copy link
Contributor

Choose a reason for hiding this comment

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

As I wrote above, I doubt that chrono is increasing our compile times too much, and with javascript methods I'm always wary about the implementation (though nowadays runtimes are usually very well implemented, perhaps that's just the cranky old man in me speaking 😄).

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@mankinskin
Copy link
Author

Sorry I forgot about this PR. Resolved the conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants