colored icon indicating copy to clipboard operation
colored copied to clipboard

Can't see colors in journalctl

Open alex-lavriv opened this issue 3 years ago • 1 comments

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!

alex-lavriv avatar Sep 13 '22 06:09 alex-lavriv

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.

hwittenborn avatar Jul 01 '23 14:07 hwittenborn