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

Driver logging: disable colors when logging to file #78435

Closed
RalfJung opened this issue Oct 27, 2020 · 14 comments · Fixed by #78548 or #80887
Closed

Driver logging: disable colors when logging to file #78435

RalfJung opened this issue Oct 27, 2020 · 14 comments · Fixed by #78548 or #80887
Assignees
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@RalfJung
Copy link
Member

When debugging a large Miri trace, I like to put the trace into a file that I can analyze and search through in an editor. Unfortunately, since the recent logging changes, that leads to a lot of garbage in the file:

2:rustc│ │ │ │ │ │ ├─�[2m0�[0m�[2mms�[0m �[1;32m INFO�[0m �[2mrustc_mir::interpret::step�[0m Retag([fn entry] _1)
2:rustc│ │ │ │ │ │ ├─�[2m0�[0m�[2mms�[0m �[1;32m INFO�[0m �[2mrustc_mir::interpret::step�[0m StorageLive(_2)
2:rustc│ │ │ │ │ │ ├─�[2m0�[0m�[2mms�[0m �[1;32m INFO�[0m �[2mrustc_mir::interpret::step�[0m StorageLive(_3)
2:rustc│ │ │ │ │ │ ├─�[2m0�[0m�[2mms�[0m �[1;32m INFO�[0m �[2mrustc_mir::interpret::step�[0m _3 = move _1
2:rustc│ │ │ │ │ │ ├─�[2m0�[0m�[2mms�[0m �[1;32m INFO�[0m �[2mrustc_mir::interpret::step�[0m Retag(_3)
2:rustc│ │ │ │ │ │ ├─�[2m0�[0m�[2mms�[0m �[1;32m INFO�[0m �[2mrustc_mir::interpret::step�[0m _2 = std::mem::ManuallyDrop::<std::boxed::Box<T, A>>::new(move _3) -> [return: bb1, unwind: bb5]
2:rustc│ │ │ │ │ │ ├┐�[2mrustc_mir::interpret::eval_context�[0m::�[1;32mframe�[0m std::boxed::Box::<alloc::collections::btree::node::LeafNode<std::string::String, i32>>::into_unique
2:rustc│ │ │ │ │ │ │└┐�[2mrustc_mir::interpret::eval_context�[0m::�[1;32mframe�[0m std::mem::ManuallyDrop::<std::boxed::Box<alloc::collections::btree::node::LeafNode<std::string::String, i32>>>::new
2:rustc│ │ │ │ │ │ │ ├─�[2m0�[0m�[2mms�[0m �[1;32m INFO�[0m �[2mrustc_mir::interpret::step�[0m // executing bb0
2:rustc│ │ │ │ │ │ │ ├─�[2m0�[0m�[2mms�[0m �[1;32m INFO�[0m �[2mrustc_mir::interpret::step�[0m Retag([fn entry] _1)
2:rustc│ │ │ │ │ │ │ ├─�[2m0�[0m�[2mms�[0m �[1;32m INFO�[0m �[2mrustc_mir::interpret::step�[0m StorageLive(_2)
2:rustc│ │ │ │ │ │ │ ├─�[2m0�[0m�[2mms�[0m �[1;32m INFO�[0m �[2mrustc_mir::interpret::step�[0m _2 = move _1
2:rustc│ │ │ │ │ │ │ ├─�[2m0�[0m�[2mms�[0m �[1;32m INFO�[0m �[2mrustc_mir::interpret::step�[0m Retag(_2)

Looks like the color escape sequences are printed even when redirecting to a file. This makes working with the logfile much harder than it was before. Is there a way to fix that?

Cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Oct 27, 2020

This is the fault of

.with_ansi(true)

I should be checking for whether the terminal supports colors before activating colors

@oli-obk
Copy link
Contributor

oli-obk commented Oct 27, 2020

A workaround until then is to use https://superuser.com/a/380778

@camelid camelid added the A-miri Area: The miri tool label Oct 28, 2020
@camelid camelid self-assigned this Oct 28, 2020
@camelid camelid added A-driver Area: rustc_driver that ties everything together into the `rustc` compiler and removed A-miri Area: The miri tool labels Oct 28, 2020
@camelid camelid changed the title Miri engine logging: disable colors when logging to file Driver logging: disable colors when logging to file Oct 28, 2020
@camelid
Copy link
Member

camelid commented Oct 29, 2020

How can I run miri from the rust repo? (i.e. built using ./x.py build)

@RalfJung
Copy link
Member Author

You can run the test suite with ./x.py test --stage 0 src/tools/miri, but that's not what you were asking... that's not supported yet unfortunately: #76666

@RalfJung
Copy link
Member Author

Until then, you'll have to resort to this.

Some of the x.py commands might need adjusting though as x.py changed.

@camelid
Copy link
Member

camelid commented Oct 29, 2020

Ah, thanks! I forgot about that part of the docs :)

@camelid
Copy link
Member

camelid commented Oct 29, 2020

Hmm, I'm getting this error:

error[E0463]: can't find crate for `rustc_attr`
  --> src/lib.rs:14:1
   |
14 | extern crate rustc_attr;
   | ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

I'm using the latest master rustc and the latest miri. Is miri broken right now?

EDIT: Oh, I think I need --stage 2.

@RalfJung
Copy link
Member Author

Yeah looks like you are using the wrong stage or so. The docs are from back when stage 2 was the default...

@camelid camelid added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Oct 29, 2020
camelid added a commit to camelid/rust that referenced this issue Oct 29, 2020
bors added a commit to rust-lang/miri that referenced this issue Oct 30, 2020
Update locally-built rustc instructions

Cc rust-lang/rust#78435
@bors bors closed this as completed in 1c389ff Nov 24, 2020
@RalfJung
Copy link
Member Author

@oli-obk @camelid I'm afraid the problem was not solved by that PR. When I run Miri like this locally

MIRI_LOG=info,miri::stacked_borrows=trace ./miri run /tmp/test.rs -Zmiri-track-raw-pointers 2> log

I still get all the ANSI codes in that logfile, which makes the file very hard to work with.

@RalfJung RalfJung reopened this Jan 10, 2021
@RalfJung
Copy link
Member Author

Looks like the code tests stdout_isatty, but logging goes to stderr so this is the wrong test.

@camelid
Copy link
Member

camelid commented Jan 10, 2021

Hmm, I guess I didn't notice any issues because I always redirect stderr to stdout and then view that.

@camelid
Copy link
Member

camelid commented Jan 10, 2021

Working on a fix.

@RalfJung
Copy link
Member Author

RalfJung commented Jan 10, 2021

Yeah, for now using &>log to redirect both to the logfile is an okay work-around.

@jyn514
Copy link
Member

jyn514 commented Jan 11, 2021

@RalfJung FYI you can view the original color with less -R, which prints them directly to the terminal. That doesn't work in an editor, though.

@bors bors closed this as completed in 293a491 Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
4 participants