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

Add support for disabling ansi color when the feature is enabled #16

Merged
merged 2 commits into from
Aug 5, 2024

Conversation

fredr
Copy link
Contributor

@fredr fredr commented Jul 22, 2024

Checklist

  • I have read the Contributor Guide
  • I have read and agree to the Code of Conduct
  • I have added a description of my changes and why I'd like them included in the section below

Description of Changes

Adds support for disabling ansi colors (via with_ansi_color) when the ansi_logs feature is enabled. It also defaults to only emitting colors if stdout is a terminal.

I also added with_timestamp, so it is possible to disable timestamps, mainly to make it easier to write tests.

Related Issues

Fixes #15

@fredr fredr requested a review from bwestlin as a code owner July 22, 2024 18:37
@fredr fredr force-pushed the fredr/disable-ansi-color branch from 08351fe to 8e07471 Compare July 22, 2024 18:43
@flokli
Copy link

flokli commented Jul 31, 2024

Thanks! Just tested this, does the right thing out of the box!

Used a systemd-run invocation to properly detach it from the terminal.

Copy link
Member

@bwestlin bwestlin left a comment

Choose a reason for hiding this comment

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

👍 Nice! Looks good!

src/formatter.rs Outdated Show resolved Hide resolved
Co-authored-by: Björn Westlin <[email protected]>
@bwestlin bwestlin merged commit 0305c77 into EmbarkStudios:main Aug 5, 2024
6 checks passed
@flokli
Copy link

flokli commented Aug 5, 2024

Thanks! Can you tag a release with this?

@fredr fredr deleted the fredr/disable-ansi-color branch August 5, 2024 10:58
@fredr
Copy link
Contributor Author

fredr commented Aug 5, 2024

Thanks! Can you tag a release with this?

@flokli It was released by @bwestlin as v0.3.5 🚢

flokli added a commit to flokli/mycelium that referenced this pull request Aug 5, 2024
This will cause to be outputted with color in case the output is a
terminal, but will refrain from doing so if it's run by a service
manager.

Follow-up to threefoldtech#316, unblocked by
EmbarkStudios/tracing-logfmt#16
LeeSmet pushed a commit to threefoldtech/mycelium that referenced this pull request Aug 19, 2024
This will cause to be outputted with color in case the output is a
terminal, but will refrain from doing so if it's run by a service
manager.

Follow-up to #316, unblocked by
EmbarkStudios/tracing-logfmt#16
maximevanhees pushed a commit to threefoldtech/mycelium that referenced this pull request Aug 21, 2024
This will cause to be outputted with color in case the output is a
terminal, but will refrain from doing so if it's run by a service
manager.

Follow-up to #316, unblocked by
EmbarkStudios/tracing-logfmt#16
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.

ansi_logs enables colors unconditionally, even if output is not a terminal
3 participants