Skip to content

Driver logging: disable colors when logging to file #78435

Description

@RalfJung

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

Activity

  1. oli-obk commented on Oct 27, 2020

    @oli-obk
    Contributor

    This is the fault of

    .with_ansi(true)

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

  2. oli-obk commented on Oct 27, 2020

    @oli-obk
    Contributor

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

  3. self-assigned this
    on Oct 28, 2020
  4. added
    A-driverArea: rustc_driver that ties everything together into the `rustc` compiler
    and removed
    A-miriArea: The miri tool
    on Oct 28, 2020
  5. changed the title [-]Miri engine logging: disable colors when logging to file[/-] [+]Driver logging: disable colors when logging to file[/+] on Oct 28, 2020
  6. camelid commented on Oct 29, 2020

    @camelid
    Member

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

  7. RalfJung commented on Oct 29, 2020

    @RalfJung
    MemberAuthor

    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

  8. RalfJung commented on Oct 29, 2020

    @RalfJung
    MemberAuthor

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

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

  9. camelid commented on Oct 29, 2020

    @camelid
    Member

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

  10. camelid commented on Oct 29, 2020

    @camelid
    Member

    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.

  11. RalfJung commented on Oct 29, 2020

    @RalfJung
    MemberAuthor

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

  12. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Oct 29, 2020
  13. added a commit that references this issue on Oct 30, 2020
  14. RalfJung commented on Jan 10, 2021

    @RalfJung
    MemberAuthor

    @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.

  15. RalfJung commented on Jan 10, 2021

    @RalfJung
    MemberAuthor

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

  16. camelid commented on Jan 10, 2021

    @camelid
    Member

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

  17. camelid commented on Jan 10, 2021

    @camelid
    Member

    Working on a fix.

  18. RalfJung commented on Jan 10, 2021

    @RalfJung
    MemberAuthor

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

  19. jyn514 commented on Jan 11, 2021

    @jyn514
    Member

    @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.

  20. added a commit that references this issue on Jan 11, 2021
    293a491
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-driverArea: rustc_driver that ties everything together into the `rustc` compilerC-enhancementCategory: An issue proposing an enhancement or a PR with one.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions