Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
wincolor_sink.h
Go to the documentation of this file.
1//
2// Copyright(c) 2016 spdlog
3// Distributed under the MIT License (http://opensource.org/licenses/MIT)
4//
5
6#pragma once
7
8#include "base_sink.h"
9#include "../details/null_mutex.h"
10#include "../common.h"
11
12#include <mutex>
13#include <string>
14#include <map>
15#include <wincon.h>
16
17namespace spdlog
18{
19namespace sinks
20{
21/*
22 * Windows color console sink. Uses WriteConsoleA to write to the console with colors
23 */
24template<class Mutex>
25class wincolor_sink: public base_sink<Mutex>
26{
27public:
28 const WORD BOLD = FOREGROUND_INTENSITY;
29 const WORD RED = FOREGROUND_RED;
30 const WORD CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE;
31 const WORD WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
32 const WORD YELLOW = FOREGROUND_RED | FOREGROUND_GREEN;
33 const WORD GREEN = FOREGROUND_GREEN;
34
36 {
41 colors_[level::err] = RED | BOLD; // red bold
42 colors_[level::critical] = BACKGROUND_RED | WHITE | BOLD; // white bold on red background
43 colors_[level::off] = 0;
44 }
45
46 virtual ~wincolor_sink()
47 {
48 this->flush();
49 }
50
51 wincolor_sink(const wincolor_sink& other) = delete;
52 wincolor_sink& operator=(const wincolor_sink& other) = delete;
53
54protected:
55 virtual void _sink_it(const details::log_msg& msg) override
56 {
57 auto color = colors_[msg.level];
59 WriteConsoleA(out_handle_, msg.formatted.data(), static_cast<DWORD>(msg.formatted.size()), nullptr, nullptr);
60 SetConsoleTextAttribute(out_handle_, orig_attribs); //reset to orig colors
61 }
62
63 virtual void _flush() override
64 {
65 // windows console always flushed?
66 }
67
68 // change the color for the given level
69 void set_color(level::level_enum level, WORD color)
70 {
73 }
74
75private:
77 std::map<level::level_enum, WORD> colors_;
78
79 // set color and return the orig console attributes (for resetting later)
80 WORD set_console_attribs(WORD attribs)
81 {
85 // retrieve the current background color
86 back_color &= ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
87 // keep the background color unchanged
89 return orig_buffer_info.wAttributes; //return orig attribs
90 }
91};
92
93//
94// windows color console to stdout
95//
96template<class Mutex>
98{
99public:
101 {}
102};
103
106
107//
108// windows color console to stderr
109//
110template<class Mutex>
112{
113public:
115 {}
116};
117
120
121}
122}
wincolor_sink(const wincolor_sink &other)=delete
void set_color(level::level_enum level, WORD color)
virtual void _sink_it(const details::log_msg &msg) override
wincolor_sink & operator=(const wincolor_sink &other)=delete
WORD set_console_attribs(WORD attribs)
virtual void _flush() override
wincolor_sink(HANDLE std_handle)
std::map< level::level_enum, WORD > colors_
wincolor_stderr_sink< std::mutex > wincolor_stderr_sink_mt
wincolor_stdout_sink< details::null_mutex > wincolor_stdout_sink_st
wincolor_stderr_sink< details::null_mutex > wincolor_stderr_sink_st
wincolor_stdout_sink< std::mutex > wincolor_stdout_sink_mt
Definition json.hpp:4518