colored
colored copied to clipboard
Can't see colors in journalctl
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

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

Thanks!
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.