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

Redirect all logs to file when MM_LOG is set. #754

Closed
artemii235 opened this issue Nov 26, 2020 · 6 comments
Closed

Redirect all logs to file when MM_LOG is set. #754

artemii235 opened this issue Nov 26, 2020 · 6 comments
Assignees

Comments

@artemii235
Copy link
Member

artemii235 commented Nov 26, 2020

There're some deps now that use log crate for logging and this output is not forwarded to log file. We need to find a way to forward them too because they can contain very important information about what's going on in libp2p behaviours.

@sergeyboyko0791
Copy link

Changes were pushed into mm2.1 branch.
I think we can keep this issue opened until the features is tested

@artemii235
Copy link
Member Author

Well done! I like a lot that we now have both log level and location of a print, e.g.

01 09:41:22, mm2src/gossipsub/src/behaviour.rs:543] INFO IAmrelay: Adding peer: PeerId("12D3KooWMUb8S5dgco2xypT87ey7fpdfidpjTxhhkRRF24Z7mvSb") to the relay mesh

I have a question ref this: is it possible to cut path segments from log, e.g print behaviour.rs instead of mm2src/gossipsub/src/behaviour.rs etc?

@sergeyboyko0791
Copy link

sergeyboyko0791 commented Dec 1, 2020

is it possible to cut path segments from log, e.g print behaviour.rs instead of mm2src/gossipsub/src/behaviour.rs etc?

Yes, we can do this using the std::path::Path or a regex.

@sergeyboyko0791
Copy link

@artemii235 I've tried to figure out how to cut the path like behaviour.rs instead of mm2src/gossipsub/src/behaviour.rs. Seems to be easiest to fork log4rs crate (i'd like to avoid this way) or rewrite the pretty useful log4rs pattern encoder. The second way deprives us of the ability to easily customize the log formats.
Is it actually needed to cut the path? We also should not cut crates paths, because we can get lost in lib.rs] entries :D

@artemii235
Copy link
Member Author

Seems to be easiest to fork log4rs crate (I'd like to avoid this way)

Yeah, I'd like to avoid this too 🙂

Is it actually needed to cut the path?

It is ok to have the mm2src/gossipsub/src/behaviour.rs:543] path as it is quite short. But we get the full absolute path to a cargo dependency source, e.g. ~/.cargo/git/checkouts/rust-libp2p-7e56a40c55e2681f/6a5600f/protocols/ping/src/protocol.rs:108], which looks excessive.

I guess we can copy the pattern encoder and slightly customize it to cut the file path - maybe even submit a PR to log4rs then. Not a high priority so we can do this later.

@artemii235
Copy link
Member Author

@sergeyboyko0791 Thanks for implementing this 🙂

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

No branches or pull requests

2 participants