Agora  1.2.0
Agora project
ansicolor_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 
8 #include <spdlog/sinks/sink.h>
9 #include <memory>
10 #include <mutex>
11 #include <string>
12 #include <array>
13 
14 namespace spdlog {
15 namespace sinks {
16 
24 template<typename ConsoleMutex>
25 class ansicolor_sink : public sink
26 {
27 public:
28  using mutex_t = typename ConsoleMutex::mutex_t;
29  ansicolor_sink(FILE *target_file, color_mode mode);
30  ~ansicolor_sink() override = default;
31 
32  ansicolor_sink(const ansicolor_sink &other) = delete;
33  ansicolor_sink(ansicolor_sink &&other) = delete;
34 
35  ansicolor_sink &operator=(const ansicolor_sink &other) = delete;
36  ansicolor_sink &operator=(ansicolor_sink &&other) = delete;
37 
40  bool should_color();
41 
42  void log(const details::log_msg &msg) override;
43  void flush() override;
44  void set_pattern(const std::string &pattern) final;
45  void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override;
46 
47  // Formatting codes
48  const string_view_t reset = "\033[m";
49  const string_view_t bold = "\033[1m";
50  const string_view_t dark = "\033[2m";
51  const string_view_t underline = "\033[4m";
52  const string_view_t blink = "\033[5m";
53  const string_view_t reverse = "\033[7m";
54  const string_view_t concealed = "\033[8m";
55  const string_view_t clear_line = "\033[K";
56 
57  // Foreground colors
58  const string_view_t black = "\033[30m";
59  const string_view_t red = "\033[31m";
60  const string_view_t green = "\033[32m";
61  const string_view_t yellow = "\033[33m";
62  const string_view_t blue = "\033[34m";
63  const string_view_t magenta = "\033[35m";
64  const string_view_t cyan = "\033[36m";
65  const string_view_t white = "\033[37m";
66 
68  const string_view_t on_black = "\033[40m";
69  const string_view_t on_red = "\033[41m";
70  const string_view_t on_green = "\033[42m";
71  const string_view_t on_yellow = "\033[43m";
72  const string_view_t on_blue = "\033[44m";
73  const string_view_t on_magenta = "\033[45m";
74  const string_view_t on_cyan = "\033[46m";
75  const string_view_t on_white = "\033[47m";
76 
78  const string_view_t yellow_bold = "\033[33m\033[1m";
79  const string_view_t red_bold = "\033[31m\033[1m";
80  const string_view_t bold_on_red = "\033[1m\033[41m";
81 
82 private:
83  FILE *target_file_;
86  std::unique_ptr<spdlog::formatter> formatter_;
87  std::array<std::string, level::n_levels> colors_;
88  void print_ccode_(const string_view_t &color_code);
89  void print_range_(const memory_buf_t &formatted, size_t start, size_t end);
90  static std::string to_string_(const string_view_t &sv);
91 };
92 
93 template<typename ConsoleMutex>
94 class ansicolor_stdout_sink : public ansicolor_sink<ConsoleMutex>
95 {
96 public:
98 };
99 
100 template<typename ConsoleMutex>
101 class ansicolor_stderr_sink : public ansicolor_sink<ConsoleMutex>
102 {
103 public:
105 };
106 
109 
112 
113 } // namespace sinks
114 } // namespace spdlog
115 
116 #ifdef SPDLOG_HEADER_ONLY
117 # include "ansicolor_sink-inl.h"
118 #endif
fmt::v8::color
color
Definition: color.h:23
spdlog::sinks::ansicolor_sink::white
const string_view_t white
Definition: ansicolor_sink.h:65
spdlog::sinks::ansicolor_sink::dark
const string_view_t dark
Definition: ansicolor_sink.h:50
spdlog::sinks::sink
Definition: sink.h:12
spdlog::sinks::ansicolor_sink::colors_
std::array< std::string, level::n_levels > colors_
Definition: ansicolor_sink.h:87
spdlog::sinks::ansicolor_sink::clear_line
const string_view_t clear_line
Definition: ansicolor_sink.h:55
spdlog::sinks::ansicolor_sink::cyan
const string_view_t cyan
Definition: ansicolor_sink.h:64
spdlog::sinks::ansicolor_sink::set_formatter
void set_formatter(std::unique_ptr< spdlog::formatter > sink_formatter) override
Definition: ansicolor_sink-inl.h:83
spdlog::sinks::ansicolor_sink::black
const string_view_t black
Definition: ansicolor_sink.h:58
mm_gui.mode
string mode
Definition: mm_gui.py:105
spdlog::sinks::ansicolor_sink::flush
void flush() override
Definition: ansicolor_sink-inl.h:69
fmt::v8::basic_string_view
Definition: core.h:448
spdlog::level::level_enum
level_enum
Definition: common.h:211
spdlog::sinks::ansicolor_sink::to_string_
static std::string to_string_(const string_view_t &sv)
Definition: ansicolor_sink-inl.h:127
spdlog::sinks::ansicolor_sink::red
const string_view_t red
Definition: ansicolor_sink.h:59
spdlog::sinks::ansicolor_sink::should_color
bool should_color()
Definition: ansicolor_sink-inl.h:90
null_mutex.h
spdlog::sinks::ansicolor_sink::target_file_
FILE * target_file_
Definition: ansicolor_sink.h:83
fmt::v8::basic_memory_buffer
Definition: format.h:677
spdlog::sinks::ansicolor_sink::set_pattern
void set_pattern(const std::string &pattern) final
Definition: ansicolor_sink-inl.h:76
spdlog::sinks::ansicolor_sink::print_range_
void print_range_(const memory_buf_t &formatted, size_t start, size_t end)
Definition: ansicolor_sink-inl.h:121
spdlog
Definition: async.h:25
spdlog::sinks::ansicolor_sink::on_yellow
const string_view_t on_yellow
Definition: ansicolor_sink.h:71
spdlog::sinks::ansicolor_sink::on_red
const string_view_t on_red
Definition: ansicolor_sink.h:69
spdlog::sinks::ansicolor_sink::bold_on_red
const string_view_t bold_on_red
Definition: ansicolor_sink.h:80
spdlog::sinks::ansicolor_sink::yellow_bold
const string_view_t yellow_bold
Bold colors.
Definition: ansicolor_sink.h:78
spdlog::sinks::ansicolor_sink::on_cyan
const string_view_t on_cyan
Definition: ansicolor_sink.h:74
ansicolor_sink-inl.h
spdlog::sinks::ansicolor_sink::print_ccode_
void print_ccode_(const string_view_t &color_code)
Definition: ansicolor_sink-inl.h:115
start
end start
Definition: inspect_agora_results.m:95
spdlog::sinks::ansicolor_sink::yellow
const string_view_t yellow
Definition: ansicolor_sink.h:61
spdlog::sinks::ansicolor_sink::magenta
const string_view_t magenta
Definition: ansicolor_sink.h:63
spdlog::sinks::ansicolor_sink::on_white
const string_view_t on_white
Definition: ansicolor_sink.h:75
spdlog::sinks::ansicolor_sink::reset
const string_view_t reset
Definition: ansicolor_sink.h:48
spdlog::sinks::ansicolor_sink::on_black
const string_view_t on_black
Background colors.
Definition: ansicolor_sink.h:68
spdlog::sinks::ansicolor_sink::on_blue
const string_view_t on_blue
Definition: ansicolor_sink.h:72
spdlog::sinks::ansicolor_sink::underline
const string_view_t underline
Definition: ansicolor_sink.h:51
spdlog::sinks::ansicolor_sink::reverse
const string_view_t reverse
Definition: ansicolor_sink.h:53
spdlog::sinks::ansicolor_stderr_sink::ansicolor_stderr_sink
ansicolor_stderr_sink(color_mode mode=color_mode::automatic)
Definition: ansicolor_sink-inl.h:140
spdlog::sinks::ansicolor_sink::red_bold
const string_view_t red_bold
Definition: ansicolor_sink.h:79
spdlog::sinks::ansicolor_sink::set_color_mode
void set_color_mode(color_mode mode)
Definition: ansicolor_sink-inl.h:96
spdlog::details::log_msg
Definition: log_msg.h:11
sink.h
spdlog::sinks::ansicolor_sink::should_do_colors_
bool should_do_colors_
Definition: ansicolor_sink.h:85
spdlog::sinks::ansicolor_sink::on_magenta
const string_view_t on_magenta
Definition: ansicolor_sink.h:73
spdlog::sinks::ansicolor_sink::set_color
void set_color(level::level_enum color_level, string_view_t color)
Definition: ansicolor_sink-inl.h:34
spdlog::sinks::ansicolor_sink::operator=
ansicolor_sink & operator=(const ansicolor_sink &other)=delete
spdlog::sinks::ansicolor_sink::blue
const string_view_t blue
Definition: ansicolor_sink.h:62
spdlog::sinks::ansicolor_stderr_sink
Definition: ansicolor_sink.h:101
spdlog::sinks::ansicolor_sink::ansicolor_sink
ansicolor_sink(FILE *target_file, color_mode mode)
Definition: ansicolor_sink-inl.h:17
spdlog::sinks::ansicolor_stdout_sink
Definition: ansicolor_sink.h:94
spdlog::sinks::ansicolor_sink::formatter_
std::unique_ptr< spdlog::formatter > formatter_
Definition: ansicolor_sink.h:86
console_globals.h
spdlog::sinks::ansicolor_sink::concealed
const string_view_t concealed
Definition: ansicolor_sink.h:54
spdlog::sinks::ansicolor_sink::blink
const string_view_t blink
Definition: ansicolor_sink.h:52
spdlog::sinks::ansicolor_sink::mutex_t
typename ConsoleMutex::mutex_t mutex_t
Definition: ansicolor_sink.h:28
spdlog::sinks::ansicolor_sink::on_green
const string_view_t on_green
Definition: ansicolor_sink.h:70
spdlog::sinks::ansicolor_sink
Definition: ansicolor_sink.h:25
spdlog::sinks::ansicolor_sink::green
const string_view_t green
Definition: ansicolor_sink.h:60
spdlog::sinks::ansicolor_sink::log
void log(const details::log_msg &msg) override
Definition: ansicolor_sink-inl.h:41
spdlog::sinks::ansicolor_sink::~ansicolor_sink
~ansicolor_sink() override=default
spdlog::sinks::ansicolor_sink::bold
const string_view_t bold
Definition: ansicolor_sink.h:49
spdlog::color_mode::automatic
@ automatic
spdlog::sinks::ansicolor_sink::mutex_
mutex_t & mutex_
Definition: ansicolor_sink.h:84
spdlog::color_mode
color_mode
Definition: common.h:256
nlohmann::json_v3_11_1NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON::detail2::end
end_tag end(T &&...)
spdlog::sinks::ansicolor_stdout_sink::ansicolor_stdout_sink
ansicolor_stdout_sink(color_mode mode=color_mode::automatic)
Definition: ansicolor_sink-inl.h:134