gabime / spdlog

Fast C++ logging library.
Other
24.39k stars 4.55k forks source link

No Colored-Text in my program #1983

Closed hctym1995 closed 3 years ago

hctym1995 commented 3 years ago

os:linux compiler:riscv-gnu-g++

i cross-compile spodlog(V1.8.5) in my RISC-V program,but there is no Color-Text in stdout when i run program

I used to work well on windows and x86-Linux

i tried to use spdlog::set_color_mode, but it seems to have failed... :-(

gabime commented 3 years ago

which terminal are you using? Perhaps it is not in the list defined here: https://github.com/gabime/spdlog/blob/036cc5d5753169075f28425a0a63deb708d01fec/include/spdlog/details/os-inl.h#L418

hctym1995 commented 3 years ago

thanks for your quick response

I'm using xshell now

I tried it with mobaxterm. It works, but I'm not sure if it's because mobaxterm will color it automatically

hctym1995 commented 3 years ago

thanks for your quick response

I'm using xshell now

I tried it with mobaxterm. It works, but I'm not sure if it's because mobaxterm will color it automatically

i tried it with putty, no Colored-Text either

gabime commented 3 years ago

You could try exporting COLORTERM env variable before running.

hctym1995 commented 3 years ago

i tried to export COLORTERM, it doesn't work BUT i wrote "return true;" in function: SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT
(spdlog/include/spdlog/details/os-inl.h) and it works..........

hctym1995 commented 3 years ago

` SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT { return true; //i wrote here

ifdef _WIN32

    return true;
#else

static const bool result = []() {
    const char *env_colorterm_p = std::getenv("COLORTERM");
    if (env_colorterm_p != nullptr)
    {
        return true;
    }

    static constexpr std::array<const char *, 15> terms = {{"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux",
        "msys", "putty", "rxvt", "screen", "vt100", "xterm", "alacritty"}};

    const char *env_term_p = std::getenv("TERM");
    if (env_term_p == nullptr)
    {
        return false;
    }

        return std::any_of(terms.begin(), terms.end(), [&](const char *term) { return std::strstr(env_term_p, term) != nullptr; });
    }();

    return result;
#endif
}

`

gabime commented 3 years ago

As you can see in the code, if COLORTERM is found it returns true as well. If you know the TERM env var please open a pr.

hctym1995 commented 3 years ago

As you can see in the code, if COLORTERM is found it returns true as well. If you know the TERM env var please open a pr.

ok, i'll try to find it