Agora  1.2.0
Agora project
wincolor_sink.h
Go to the documentation of this file.
1 // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
3 
4 #pragma once
5 
6 #include <spdlog/common.h>
9 #include <spdlog/sinks/sink.h>
10 
11 #include <memory>
12 #include <mutex>
13 #include <string>
14 #include <array>
15 #include <cstdint>
16 
17 namespace spdlog {
18 namespace sinks {
19 /*
20  * Windows color console sink. Uses WriteConsoleA to write to the console with
21  * colors
22  */
23 template<typename ConsoleMutex>
24 class wincolor_sink : public sink
25 {
26 public:
27  wincolor_sink(void *out_handle, color_mode mode);
28  ~wincolor_sink() override;
29 
30  wincolor_sink(const wincolor_sink &other) = delete;
31  wincolor_sink &operator=(const wincolor_sink &other) = delete;
32 
33  // change the color for the given level
34  void set_color(level::level_enum level, std::uint16_t color);
35  void log(const details::log_msg &msg) final override;
36  void flush() final override;
37  void set_pattern(const std::string &pattern) override final;
38  void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override final;
40 
41 protected:
42  using mutex_t = typename ConsoleMutex::mutex_t;
43  void *out_handle_;
46  std::unique_ptr<spdlog::formatter> formatter_;
47  std::array<std::uint16_t, level::n_levels> colors_;
48 
49  // set foreground color and return the orig console attributes (for resetting later)
50  std::uint16_t set_foreground_color_(std::uint16_t attribs);
51 
52  // print a range of formatted message to console
53  void print_range_(const memory_buf_t &formatted, size_t start, size_t end);
54 
55  // in case we are redirected to file (not in console mode)
56  void write_to_file_(const memory_buf_t &formatted);
57 
59 };
60 
61 template<typename ConsoleMutex>
62 class wincolor_stdout_sink : public wincolor_sink<ConsoleMutex>
63 {
64 public:
66 };
67 
68 template<typename ConsoleMutex>
69 class wincolor_stderr_sink : public wincolor_sink<ConsoleMutex>
70 {
71 public:
73 };
74 
77 
80 } // namespace sinks
81 } // namespace spdlog
82 
83 #ifdef SPDLOG_HEADER_ONLY
84 # include "wincolor_sink-inl.h"
85 #endif
fmt::v8::color
color
Definition: color.h:23
spdlog::sinks::wincolor_stderr_sink::wincolor_stderr_sink
wincolor_stderr_sink(color_mode mode=color_mode::automatic)
Definition: wincolor_sink-inl.h:171
spdlog::sinks::sink
Definition: sink.h:12
spdlog::sinks::wincolor_sink::formatter_
std::unique_ptr< spdlog::formatter > formatter_
Definition: wincolor_sink.h:46
spdlog::sinks::wincolor_stdout_sink::wincolor_stdout_sink
wincolor_stdout_sink(color_mode mode=color_mode::automatic)
Definition: wincolor_sink-inl.h:165
spdlog::sinks::wincolor_sink
Definition: wincolor_sink.h:24
spdlog::sinks::wincolor_sink::set_color
void set_color(level::level_enum level, std::uint16_t color)
Definition: wincolor_sink-inl.h:45
spdlog::sinks::sink::level
level::level_enum level() const
Definition: sink-inl.h:22
mm_gui.mode
string mode
Definition: mm_gui.py:105
spdlog::sinks::wincolor_sink::set_foreground_color_
std::uint16_t set_foreground_color_(std::uint16_t attribs)
Definition: wincolor_sink-inl.h:126
spdlog::level::level_enum
level_enum
Definition: common.h:211
spdlog::sinks::wincolor_sink::operator=
wincolor_sink & operator=(const wincolor_sink &other)=delete
spdlog::sinks::wincolor_stdout_sink
Definition: wincolor_sink.h:62
null_mutex.h
fmt::v8::basic_memory_buffer
Definition: format.h:677
spdlog::sinks::wincolor_sink::should_do_colors_
bool should_do_colors_
Definition: wincolor_sink.h:45
spdlog::sinks::wincolor_sink::set_color_mode
void set_color_mode(color_mode mode)
Definition: wincolor_sink-inl.h:102
spdlog::sinks::wincolor_sink::set_color_mode_impl
void set_color_mode_impl(color_mode mode)
Definition: wincolor_sink-inl.h:109
spdlog::sinks::wincolor_sink::flush
void flush() final override
Definition: wincolor_sink-inl.h:82
spdlog
Definition: async.h:25
spdlog::sinks::wincolor_sink::out_handle_
void * out_handle_
Definition: wincolor_sink.h:43
spdlog::sinks::wincolor_sink::write_to_file_
void write_to_file_(const memory_buf_t &formatted)
Definition: wincolor_sink-inl.h:155
spdlog::sinks::wincolor_sink::wincolor_sink
wincolor_sink(void *out_handle, color_mode mode)
Definition: wincolor_sink-inl.h:19
start
end start
Definition: inspect_agora_results.m:95
spdlog::sinks::wincolor_sink::mutex_
mutex_t & mutex_
Definition: wincolor_sink.h:44
spdlog::sinks::wincolor_sink::set_pattern
void set_pattern(const std::string &pattern) override final
Definition: wincolor_sink-inl.h:88
common.h
spdlog::details::log_msg
Definition: log_msg.h:11
sink.h
spdlog::sinks::wincolor_sink::mutex_t
typename ConsoleMutex::mutex_t mutex_t
Definition: wincolor_sink.h:42
spdlog::sinks::wincolor_sink::set_formatter
void set_formatter(std::unique_ptr< spdlog::formatter > sink_formatter) override final
Definition: wincolor_sink-inl.h:95
spdlog::sinks::wincolor_sink::colors_
std::array< std::uint16_t, level::n_levels > colors_
Definition: wincolor_sink.h:47
console_globals.h
spdlog::sinks::wincolor_stderr_sink
Definition: wincolor_sink.h:69
spdlog::sinks::wincolor_sink::log
void log(const details::log_msg &msg) final override
Definition: wincolor_sink-inl.h:52
spdlog::color_mode::automatic
@ automatic
spdlog::sinks::wincolor_sink::~wincolor_sink
~wincolor_sink() override
Definition: wincolor_sink-inl.h:38
spdlog::sinks::wincolor_sink::print_range_
void print_range_(const memory_buf_t &formatted, size_t start, size_t end)
Definition: wincolor_sink-inl.h:144
spdlog::color_mode
color_mode
Definition: common.h:256
wincolor_sink-inl.h
nlohmann::json_v3_11_1NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON::detail2::end
end_tag end(T &&...)