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

Can't see colors in journalctl #116

Open
alex-lavriv opened this issue Sep 13, 2022 · 1 comment
Open

Can't see colors in journalctl #116

alex-lavriv opened this issue Sep 13, 2022 · 1 comment

Comments

@alex-lavriv
Copy link

I am working with Linux daemons which output stdout to journalctl.

I can see colors in C++ sample but not in Rust Sample with Colored 2.0.0

Not working sample

use colored::*;
use std::{thread, time};
fn main() {
    let five_seconds = time::Duration::from_secs(5);
    loop {
        println!("{} {} !", "it".green(), "works".blue().bold());
        thread::sleep(five_seconds);
    }
}

Working Sample

#include <iostream>
#include <unistd.h>
int main() {
  while (true) {
    std::cout << "\033[1;31mbold red text\033[0m\n";
    std::cout.flush();
    sleep(5);
  }
}

Service files

Description=CPP Printing service

[Service]
WorkingDirectory=/home/phantom-il-alex/development/color_test/src/
ExecStart= /home/phantom-il-alex/development/color_test/src/cpp_color_test
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target
[Unit]
Description=Rust Printing service

[Service]
WorkingDirectory=/home/phantom-il-alex/development/color_test/target/debug
ExecStart= /home/phantom-il-alex/development/color_test/target/debug/color_test
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

Observe output
journalctl -u test_cpp.service -fo cat
journalctl -u test_rust.service -fo cat

Output
image
image

But when running
/home/phantom-il-alex/development/color_test/target/debug/color_test
as is, the colors are shown
image

Thanks!

@hwittenborn
Copy link
Member

I'm not positive on what a TTY is, but I'm pretty sure it's just when you're using an interactive terminal, and I think this library automatically disables coloring when you're not in a TTY.

I set up CI for this project earlier and was experiencing a similar issue - could you try setting CLICOLOR_FORCE=1 in your service file and see if that fixes things up?

I'm in the middle of getting all of the issues in this repository checked at, if this isn't relevant to you anymore just let me know so I can get it closed up.

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

No branches or pull requests

2 participants