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

ANSI escape sequences multiplatform (win10, linux) #3111

Closed
yalov opened this issue Jun 16, 2024 · 2 comments
Closed

ANSI escape sequences multiplatform (win10, linux) #3111

yalov opened this issue Jun 16, 2024 · 2 comments

Comments

@yalov
Copy link

yalov commented Jun 16, 2024

Hello, It there a way to have colors set up as

trace and debug — full line gray (GRAY = "\033[90m"), not just from %^ to %$, but full line

info, warn, error, critical — full line white (normal), only the level tag is colored (default colors and a pattern se up as %^%l%$ are ok)

@tt4g
Copy link
Contributor

tt4g commented Jun 16, 2024

Related #3103

wincolor_sink is already provided that uses the old Windows color output API.
However, wincolor_sink does not use ANSI escape sequences, so you can create a custom sink if you really want to use it.

See wiki: https://github.com/gabime/spdlog/wiki/4.-Sinks#implementing-your-own-sink

stdout_color_sink and stderr_color_sink, introduced in README.md, are aliases for ansicolor_sink and wincolor_sink.

namespace spdlog {
namespace sinks {
#ifdef _WIN32
using stdout_color_sink_mt = wincolor_stdout_sink_mt;
using stdout_color_sink_st = wincolor_stdout_sink_st;
using stderr_color_sink_mt = wincolor_stderr_sink_mt;
using stderr_color_sink_st = wincolor_stderr_sink_st;
#else
using stdout_color_sink_mt = ansicolor_stdout_sink_mt;
using stdout_color_sink_st = ansicolor_stdout_sink_st;
using stderr_color_sink_mt = ansicolor_stderr_sink_mt;
using stderr_color_sink_st = ansicolor_stderr_sink_st;
#endif
} // namespace sinks

@gabime gabime closed this as completed Jun 19, 2024
@cschreib-ibex
Copy link

cschreib-ibex commented Jul 17, 2024

Unfortunately, the ANSI color sinks are not included in the static/shared library build of spdlog on Windows. The headers are there, but the implementation is missing, so trying to use these sinks results in a linker error. Looking at the source code, they should indeed work on Windows, so perhaps they should be included unconditionally in the build?

A workaround is to include both ansicolor_sink.h and ansicolor_sink-inl.h, but I don't know if this is advisable.

I have opened a new issue to cover this and other problems using this on Windows: #3138.

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

4 participants