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 3rdparty rust crate logging to be hidden #7530

Merged

Conversation

Projects
None yet
3 participants
@illicitonion
Copy link
Contributor

commented Apr 10, 2019

Some crates (particularly gitignore), and particularly at trace level
(tokio) are super verbose (e.g. logging every time the event loop
ticks), which means that in pants we either log everything at debug
level (making debug really verbose), or don't log some things that would
be useful (for fear of it being too verbose).

This enabled-by-default flag hides 3rdparty rust crate logging, enabling
us to log more verbosely at more verbose levels from our own code.

@illicitonion illicitonion requested review from stuhood and blorente Apr 10, 2019

@stuhood
Copy link
Member

left a comment

#shipit

@@ -110,6 +110,9 @@ def register_bootstrap_options(cls, register):
register('-q', '--quiet', type=bool, recursive=True, daemon=False,
help='Squelches most console output. NOTE: Some tasks default to behaving quietly: '
'inverting this option supports making them noisier than they would be otherwise.')
register('--show-rust-3rdparty-logs', type=bool, default=False, advanced=True,

This comment has been minimized.

Copy link
@stuhood

stuhood Apr 10, 2019

Member

Annoying naming nit (sorry), but: renaming this to be be more namespaced (ie --log-show-rust-3rdparty) would make the help more scannable.

@blorente
Copy link
Contributor

left a comment

Thanks, this is great!

use std::io::Write;
use std::path::PathBuf;

fn main() {

This comment has been minimized.

Copy link
@blorente

blorente Apr 15, 2019

Contributor

TIL this is a thing :)

@@ -89,3 +89,7 @@ impl From<PythonLogLevel> for log::Level {
}
}
}

mod pants_packages {
include!(concat!(env!("OUT_DIR"), "/packages.rs"));

This comment has been minimized.

Copy link
@blorente

blorente Apr 15, 2019

Contributor

Is this better than writing the names of the packages to a .txt file and reading normally?
The documentation for include! seems to hint that it's unrecommended to use it at all.
I guess this is precomputed at compile time, and would be better than something like a lazy_static! to save the overhead, so I'm okay with it, just wondering about your thoughts there.

This comment has been minimized.

Copy link
@illicitonion

illicitonion Apr 15, 2019

Author Contributor

Yeah; if we wanted to read a text file at runtime, we would need to distribute that text file alongside pants somewhere, and then we'd need to know how to locate it on disk, and then we'd need to read it from disk every time pants runs. All of that adds a lot of complexity vs just knowing this information at compile time.

The advice against using include! in https://doc.rust-lang.org/std/macro.include.html is mostly talking about concerns around scoping; in this specific example, the only symbol we're relying on being exposed to our snippet is str, so the concern is that if in logging/lib.rs we shadowed the str symbol, that shadowed version would be used (and our code probably wouldn't compile). Accordingly, technically the codegen would be more correct if it used ::std::str rather than str - I will make this change!

When you're basically generating a whole module, include! is generally fine, but it's much sketchier to use for smaller chunks of code which may be more sensitive to the surrounding context.

The other down-side of include! is that IDEs tend not to click through to it nicely; hopefully that will get resolved at some point...

This comment has been minimized.

Copy link
@illicitonion

illicitonion Apr 15, 2019

Author Contributor

... Apparently you can't absolutely qualify str (in any way that I can find), so... Leaving as-is...

@@ -156,6 +177,22 @@ impl<W: Write + Send + 'static> Log for MaybeWriteLogger<W> {
if !self.enabled(record.metadata()) {
return;
}
let mut should_log = self.show_rust_3rdparty_logs;

This comment has been minimized.

Copy link
@blorente

blorente Apr 15, 2019

Contributor

I really would like this code to go in enabled(), but I think that log::Metadata does not have module_path. Sigh.

illicitonion added some commits Apr 2, 2019

Allow 3rdparty rust crate logging to be hidden
Some crates (particularly gitignore), and particularly at trace level
(tokio) are super verbose (e.g. logging every time the event loop
ticks), which means that in pants we either log everything at debug
level (making debug really verbose), or don't log some things that would
be useful (for fear of it being too verbose).

This enabled-by-default flag hides 3rdparty rust crate logging, enabling
us to log more verbosely at more verbose levels from our own code.

@illicitonion illicitonion force-pushed the twitter:dwagnerhall/pantsd-logging-filter-rust branch from a609758 to 1ed3471 Apr 15, 2019

illicitonion added some commits Apr 15, 2019

Fix crate name check
If the lib.rs file logs, there's no :: present

@illicitonion illicitonion merged commit a3f3b0a into pantsbuild:master Apr 16, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@illicitonion illicitonion deleted the twitter:dwagnerhall/pantsd-logging-filter-rust branch Apr 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.