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

Optional logger #302

Merged
merged 5 commits into from
Oct 10, 2019
Merged

Optional logger #302

merged 5 commits into from
Oct 10, 2019

Conversation

Hoverbear
Copy link
Contributor

This builds off #288 and fixes #301 .

Could you have a look @LucioFranco ?

Exposes a (default) feature called default-logger which is our normal test_logger just exposed publicly, it's used when None is passed as a logger to RawNode or Raft.

I am not sure about the exact details about what default_logger should look like, but it seems to work fine if I use it as the logger in five_mem_node.

Signed-off-by: Ana Hobden <operator@hoverbear.org>
@Hoverbear Hoverbear requested a review from hicqu October 7, 2019 23:02
@Hoverbear Hoverbear self-assigned this Oct 7, 2019
src/raw_node.rs Outdated
@@ -216,10 +216,14 @@ pub struct RawNode<T: Storage> {
prev_hs: HardState,
}

impl<T: Storage> RawNode<T> {
impl<'a, T: Storage> RawNode<T> {

Choose a reason for hiding this comment

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

Do you want to tie this lifetime to the fn not the impl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yes, you're right! Thanks!

@BusyJay
Copy link
Member

BusyJay commented Oct 8, 2019

I think just showing how to construct a default logger in example is enough. The purpose to require slog logger is to simplify dependencies and interfaces. This PR just defeats the goal.

hicqu
hicqu previously approved these changes Oct 8, 2019
@hicqu
Copy link
Contributor

hicqu commented Oct 8, 2019

LGTM.

@Hoverbear
Copy link
Contributor Author

@BusyJay The case @LucioFranco originally brought up was that they did not wish to use slog in their own program. I think that's a valid case and our current design prevents this. Choice in consensus library should dictate your choice in logger.

This allows downstreams like TiKV to opt out of this part of the dependency graph easily, while still allowing users who prefer libraries like tokio-tracing to use it without hacks by falling back to the standard log adapters.

I'd prefer to see this PR be an overall migration to tokio-tracing, but that's a bigger task in general.

Copy link
Member

@BusyJay BusyJay left a comment

Choose a reason for hiding this comment

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

Now that log supports kv interfaces, I think we need to switch back to log crate for the long term.

src/raft.rs Outdated
let logger = logger.new(o!("raft_id" => c.id));

let logger = logger.into();
#[cfg(feature = "default-logger")]
Copy link
Member

Choose a reason for hiding this comment

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

How about providing a new function with_default_logger instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I think having new(config, store).with_logger(x) or new(config, store).with_default_logger() is good :)

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I mean with_default_logger works like with_capacity as a constructor.

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 don't think this is a better solution but since it doesn't really matter (We'll move off slog later anyways) letr's do it your way and get this merged.

@Hoverbear
Copy link
Contributor Author

Absolutely agree Jay. :)

@Hoverbear
Copy link
Contributor Author

@BusyJay I was tracking support right now, and it seems like log -> slog structured conversion may do mallocs right now according to rust-lang/log#328 (comment). It may be worth us using this interm solution for now.

@LucioFranco
Copy link

@Hoverbear I think you're right. Sounds like we are very close to getting it in but its not ready yet. I would say this solution seems fine by me. I will also say for now I've written a simple slog -> tracing logger that works just fine and this should also work well for going from slog -> log.

@Hoverbear
Copy link
Contributor Author

OK, great, I'll update this PR with #302 (comment) and we can merge this :)

Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
@hicqu hicqu merged commit 9ab43a6 into tikv:master Oct 10, 2019
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.

Allow users to not pass a slog logger for RawNode
4 participants