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

Allow logging as optional feature #26

Merged
merged 5 commits into from
Jan 25, 2024

Conversation

cmleinz
Copy link
Contributor

@cmleinz cmleinz commented Jan 14, 2024

Request to add logging and the log crate as an optional feature enabled as a default feature to help with backwards compatibility.

Copy link
Owner

@craftytrickster craftytrickster left a comment

Choose a reason for hiding this comment

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

This makes sense if someone did not want to use logging, or perhaps if someone wanted to use the tokio tracing backend instead of the log crate.

What did you mean though exactly about backwards compatibility?

src/log.rs Outdated
@@ -0,0 +1,8 @@
macro_rules! logc {
Copy link
Owner

Choose a reason for hiding this comment

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

It is a bit repetitive, but I think it might be nicer if you simply re-exported all of the log methods (error, warn, info, debug, trace) in this file. If you did that, then when you go to consume it, you wouldn't have to import both crate::log::logc in addition to log::level (behind a feature gate). You could just import logc and use its corresponding macro methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I'll make that change.

@cmleinz
Copy link
Contributor Author

cmleinz commented Jan 14, 2024

In case someone was depending on the logging events in some way, this change shouldn't affect them. Since the logging feature will still be enabled by default. Consumers would need to opt out, via the default-features flag to not have the logging.

src/tokio/io.rs Outdated
@@ -160,16 +160,16 @@ where
let mut result = Err(e);

for (i, duration) in (options.retries_to_attempt_fn)().enumerate() {
let reconnect_num = i + 1;
let _reconnect_num = i + 1;
Copy link
Owner

Choose a reason for hiding this comment

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

I do not think these need to be changed to lead with _

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to that to avoid rustc warnings for unused variables when compiling without logging. Those variables are only used in the log statements. Up to you how you want to handle the warnings, I can remove the underscores if you want

Copy link
Owner

Choose a reason for hiding this comment

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

We shouldn't put the burden on the code here, that should be something covered in the macros itself, perhaps with an allow unused macro in the logging macros you created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be resolve in 6887535

src/tokio/io.rs Outdated
@@ -236,11 +236,11 @@ where
let future_instant = sleep(next_duration);

reconnect_status.attempts_tracker.attempt_num += 1;
let cur_num = reconnect_status.attempts_tracker.attempt_num;
let _cur_num = reconnect_status.attempts_tracker.attempt_num;
Copy link
Owner

Choose a reason for hiding this comment

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

_

src/tokio/io.rs Outdated
@@ -256,7 +256,7 @@ where
}

fn poll_disconnect(mut self: Pin<&mut Self>, cx: &mut Context) {
let (attempt, attempt_num) = match &mut self.status {
let (attempt, _attempt_num) = match &mut self.status {
Copy link
Owner

Choose a reason for hiding this comment

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

_

src/tokio/io.rs Outdated
@@ -273,8 +273,8 @@ where
(self.options.on_connect_callback)();
self.underlying_io = underlying_io;
}
Poll::Ready(Err(err)) => {
error!("Connection attempt #{} failed: {:?}", attempt_num, err);
Poll::Ready(Err(_err)) => {
Copy link
Owner

Choose a reason for hiding this comment

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

_

@craftytrickster
Copy link
Owner

Can you bump patch version?

@craftytrickster craftytrickster merged commit f451cfe into craftytrickster:main Jan 25, 2024
1 check passed
@craftytrickster
Copy link
Owner

published

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.

3 participants