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

Migrate from log to tracing #59

Closed
wants to merge 9 commits into from
Closed

Migrate from log to tracing #59

wants to merge 9 commits into from

Conversation

Finomnis
Copy link
Owner

This is a continuation of #58.

}
GracefulShutdownError::ShutdownTimeout(_) => {
log::warn!("Shutdown timed out.")
sum.push_str(format!("Shutdown timed out.\n").as_str());

Check warning

Code scanning / clippy

useless use of `format!`

useless use of `format!`
}
MyError::WithoutData => {
log::warn!(" It failed with MyError::WithoutData")
sum.push_str(
format!(" It failed with MyError::WithoutData\n").as_str(),

Check warning

Code scanning / clippy

useless use of `format!`

useless use of `format!`
if let Err(e) = &errors {
match e {
GracefulShutdownError::SubsystemsFailed(_) => {
log::warn!("Subsystems failed.")
sum.push_str(format!("Subsystems failed.\n").as_str());

Check warning

Code scanning / clippy

useless use of `format!`

useless use of `format!`
@@ -94,38 +101,45 @@ async fn main() -> Result<(), miette::Report> {
.handle_shutdown_requests(Duration::from_millis(500))
.await;

let mut sum = String::new();
Copy link
Owner Author

Choose a reason for hiding this comment

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

After reading a bit online, it seems that multiple messages are preferred over one multi-line message. Multi-line messages seem quite discouraged.

@@ -22,20 +22,20 @@
//! ```
//! use miette::Result;
//! use tokio_graceful_shutdown::{SubsystemHandle, Toplevel};
//! use env_logger::{Builder, Env};
//!
Copy link
Owner Author

Choose a reason for hiding this comment

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

Remove empty line

@@ -48,7 +48,7 @@
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! // Init logging
//! Builder::from_env(Env::default().default_filter_or("debug")).init();
//! tracing_subscriber::fmt().pretty().with_max_level(tracing::Level::DEBUG).init();
Copy link
Owner Author

Choose a reason for hiding this comment

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

remove pretty

Err(SubsystemError::Panicked(name)) => {
log::error!("Subsystem '{}' panicked", name);
Err(SubsystemError::Panicked(_)) => {
tracing::error!("Subsystem panicked");
Copy link
Owner Author

Choose a reason for hiding this comment

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

Revert those changes, spans won't cover this one

tracing_subscriber::fmt()
.pretty()
.with_max_level(tracing::Level::DEBUG)
.init();
Copy link
Owner Author

@Finomnis Finomnis Apr 22, 2023

Choose a reason for hiding this comment

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

I'm not sure, but I think this one specifically disabled logging, so the behaviour changed here.

@@ -251,7 +254,8 @@ impl<ErrType: ErrTypeTraits> Toplevel<ErrType> {
let cancel_on_timeout = async {
// Wait for the timeout to happen
tokio::time::sleep(shutdown_timeout).await;
log::error!("Shutdown timed out. Attempting to cleanup stale subsystems ...");

tracing::error!("Shutdown timed out. Attempting to cleanup stale subsystems ...",);
Copy link
Owner Author

Choose a reason for hiding this comment

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

Remove comma

}
tracing::debug!("{}", log_message);
Copy link
Owner Author

Choose a reason for hiding this comment

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

Leave as-is. After doing some research it seems that multi-line logs are quite discouraged, and multiple single-line logs are preferred.

@Finomnis
Copy link
Owner Author

I will leave this PR stale for now, as I don't have much time. Might come back to it at some point.

@Finomnis Finomnis marked this pull request as draft April 22, 2023 08:20
@h7kanna
Copy link

h7kanna commented May 11, 2023

What is remaining to do in this PR?

@Finomnis
Copy link
Owner Author

What is remaining to do in this PR?

Are you interested in it? I primarily stopped implementing it because nobody depended on it any more. But I can continue if people want it ;)

@h7kanna
Copy link

h7kanna commented May 11, 2023

Checking out your crate, but I am using tracing.
Saw this PR pending. It is not crucial, but it will just make the dependency tree not have log

@Finomnis
Copy link
Owner Author

Checking out your crate, but I am using tracing. Saw this PR pending. It is not crucial, but it will just make the dependency tree not have log

I see. So the tracing-log adapter would not be an option for you?

@Finomnis
Copy link
Owner Author

Will close this for now due to lack of time and interest.

@Finomnis Finomnis closed this Jun 21, 2023
@Finomnis
Copy link
Owner Author

Finomnis commented Oct 22, 2023

@h7kanna I did a full rewrite, and it is now tracing based. Published as 0.14.0. Just FYI.

@Finomnis Finomnis deleted the tracing branch October 22, 2023 18:03
@h7kanna
Copy link

h7kanna commented Oct 22, 2023

Yes I was watching your rewrite 👏

@Finomnis
Copy link
Owner Author

Finomnis commented Oct 22, 2023

Yes I was watching your rewrite 👏

Nice :) feel free to give me some feedback regarding whether you run into any problems with it.

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

Successfully merging this pull request may close these issues.

None yet

3 participants