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

Log with color to file #251

Open
aklitzke opened this issue Jan 6, 2020 · 6 comments
Open

Log with color to file #251

aklitzke opened this issue Jan 6, 2020 · 6 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. slog-term crate: slog-term

Comments

@aklitzke
Copy link

aklitzke commented Jan 6, 2020

More a feature request than a bug, but it would be nice to have a way to log to a generic stream using the colors implemented in slog_term::TermDecorator. Right now you have to reimplement the entire thing to get terminal colors to log to a file.

This is useful when logging to a file which is later tail -F'd.

@dpc
Copy link
Collaborator

dpc commented Jan 6, 2020

I wonder if slog_term has some environment variable way to force color. I don't think it does, but it would be worth to have. I'll be happy to land.

@aklitzke
Copy link
Author

aklitzke commented Jan 6, 2020

Thanks!!

Looking at the source it doesn't look like there's a way to force color. Colors are appended in the impl RecordDecorator for TermRecordDecorator, and TermRecordDecorator requires either a stdout or stderr terminal connection.

@agodnic
Copy link

agodnic commented Jan 17, 2020

Hi!

I'm running under supervisord a binary that logs colored output, but the log files are not colored. My guess is that slog detects that the output is not being sent to stdout and chooses not to log with colors. Having the option to force color would solve this.

@dpc
Copy link
Collaborator

dpc commented Jan 17, 2020

On Linux the color is achieved by outputting VT100 escape sequences. Most text editors will not actually display colors when you open a file with these sequences. You'll just see the output inter-winded with bunch of garbage.

Just setting the expectations right. :)

@agodnic
Copy link

agodnic commented Feb 20, 2020

In my particular case, the logs are so huge that I don't even open them with an editor - all reading is done with tools like grep, tail, etc which seem to work well with VT100 escape sequences.

On Linux the color is achieved by outputting VT100 escape sequences. Most text editors will not actually display colors when you open a file with these sequences. You'll just see the output inter-winded with bunch of garbage.

Just setting the expectations right. :)

That said, I think it would be a good idea to add this remark to the documentation if the feature is implemented.

@Techcable Techcable added C-feature-request Category: A feature request, i.e: not implemented / a PR. slog-term crate: slog-term labels Feb 10, 2022
@sunshowers
Copy link

Hey -- I was looking for this feature today. Not sure what the current status of this is, but I wanted to say that many non-terminal environments understand VT100 sequences (aka ANSI color codes) these days. An example is GitHub Actions CI.

There are also semi-standard environment variables now understood, such as CLICOLOR_FORCE. https://github.com/zkat/supports-color/blob/5973c20f106c6d0bf3fde67eb312a0df4e84bd4e/src/lib.rs#L37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. slog-term crate: slog-term
Projects
None yet
Development

No branches or pull requests

5 participants