#1278: Allow forcing ansicolor sinks on Windows

pull/1279/head
Raul Tambre 6 years ago
parent 4858d7e454
commit f89cf97596

@ -67,6 +67,7 @@ option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
if(WIN32) if(WIN32)
option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF) option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF)
option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF) option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
option(SPDLOG_FORCE_ANSICOLOR "Use VT100 instead of winapi for colored sinks" OFF)
endif() endif()
option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF) option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF)
@ -150,6 +151,11 @@ if(SPDLOG_WCHAR_SUPPORT)
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_FILENAMES) target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_FILENAMES)
endif() endif()
if(WIN32 AND NOT SPDLOG_FORCE_ANSICOLOR)
target_compile_definitions(spdlog PUBLIC SPDLOG_WINCOLOR)
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WINCOLOR)
endif()
if(SPDLOG_NO_EXCEPTIONS) if(SPDLOG_NO_EXCEPTIONS)
target_compile_definitions(spdlog PUBLIC SPDLOG_NO_EXCEPTIONS) target_compile_definitions(spdlog PUBLIC SPDLOG_NO_EXCEPTIONS)

@ -14,7 +14,7 @@
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER #ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
// support for the default stdout color logger // support for the default stdout color logger
#ifdef _WIN32 #ifdef SPDLOG_WINCOLOR
#include "spdlog/sinks/wincolor_sink.h" #include "spdlog/sinks/wincolor_sink.h"
#else #else
#include "spdlog/sinks/ansicolor_sink.h" #include "spdlog/sinks/ansicolor_sink.h"
@ -36,7 +36,7 @@ SPDLOG_INLINE registry::registry()
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER #ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
// create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows). // create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows).
#ifdef _WIN32 #ifdef SPDLOG_WINCOLOR
auto color_sink = std::make_shared<sinks::wincolor_stdout_sink_mt>(); auto color_sink = std::make_shared<sinks::wincolor_stdout_sink_mt>();
#else #else
auto color_sink = std::make_shared<sinks::ansicolor_stdout_sink_mt>(); auto color_sink = std::make_shared<sinks::ansicolor_stdout_sink_mt>();

@ -3,7 +3,7 @@
#pragma once #pragma once
#ifdef _WIN32 #ifdef SPDLOG_WINCOLOR
#include "spdlog/sinks/wincolor_sink.h" #include "spdlog/sinks/wincolor_sink.h"
#else #else
#include "spdlog/sinks/ansicolor_sink.h" #include "spdlog/sinks/ansicolor_sink.h"
@ -13,7 +13,7 @@
namespace spdlog { namespace spdlog {
namespace sinks { namespace sinks {
#ifdef _WIN32 #ifdef SPDLOG_WINCOLOR
using stdout_color_sink_mt = wincolor_stdout_sink_mt; using stdout_color_sink_mt = wincolor_stdout_sink_mt;
using stdout_color_sink_st = wincolor_stdout_sink_st; using stdout_color_sink_st = wincolor_stdout_sink_st;
using stderr_color_sink_mt = wincolor_stderr_sink_mt; using stderr_color_sink_mt = wincolor_stderr_sink_mt;

@ -12,7 +12,7 @@
// //
// color sinks // color sinks
// //
#ifdef _WIN32 #ifdef SPDLOG_WINCOLOR
#include "spdlog/sinks/wincolor_sink-inl.h" #include "spdlog/sinks/wincolor_sink-inl.h"
template class spdlog::sinks::wincolor_sink<spdlog::details::console_mutex>; template class spdlog::sinks::wincolor_sink<spdlog::details::console_mutex>;
template class spdlog::sinks::wincolor_sink<spdlog::details::console_nullmutex>; template class spdlog::sinks::wincolor_sink<spdlog::details::console_nullmutex>;

Loading…
Cancel
Save