Photon 1.0.0
Loading...
Searching...
No Matches
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
14namespace spdlog
15{
16 namespace sinks
17 {
18
26 template <typename ConsoleMutex>
27 class ansicolor_sink : public sink
28 {
29 public:
30 using mutex_t = typename ConsoleMutex::mutex_t;
31 ansicolor_sink(FILE* target_file, color_mode mode);
32 ~ansicolor_sink() override = default;
33
34 ansicolor_sink(const ansicolor_sink& other) = delete;
35 ansicolor_sink(ansicolor_sink&& other) = delete;
36
37 ansicolor_sink& operator=(const ansicolor_sink& other) = delete;
39
41 void set_color_mode(color_mode mode);
42 bool should_color();
43
44 void log(const details::log_msg& msg) override;
45 void flush() override;
46 void set_pattern(const std::string& pattern) final;
47 void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override;
48
49 // Formatting codes
50 const string_view_t reset = "\033[m";
51 const string_view_t bold = "\033[1m";
52 const string_view_t dark = "\033[2m";
53 const string_view_t underline = "\033[4m";
54 const string_view_t blink = "\033[5m";
55 const string_view_t reverse = "\033[7m";
56 const string_view_t concealed = "\033[8m";
57 const string_view_t clear_line = "\033[K";
58
59 // Foreground colors
60 const string_view_t black = "\033[30m";
61 const string_view_t red = "\033[31m";
62 const string_view_t green = "\033[32m";
63 const string_view_t yellow = "\033[33m";
64 const string_view_t blue = "\033[34m";
65 const string_view_t magenta = "\033[35m";
66 const string_view_t cyan = "\033[36m";
67 const string_view_t white = "\033[37m";
68
70 const string_view_t on_black = "\033[40m";
71 const string_view_t on_red = "\033[41m";
72 const string_view_t on_green = "\033[42m";
73 const string_view_t on_yellow = "\033[43m";
74 const string_view_t on_blue = "\033[44m";
75 const string_view_t on_magenta = "\033[45m";
76 const string_view_t on_cyan = "\033[46m";
77 const string_view_t on_white = "\033[47m";
78
80 const string_view_t yellow_bold = "\033[33m\033[1m";
81 const string_view_t red_bold = "\033[31m\033[1m";
82 const string_view_t bold_on_red = "\033[1m\033[41m";
83
84 private:
88 std::unique_ptr<spdlog::formatter> formatter_;
89 std::array<std::string, level::n_levels> colors_;
90 void print_ccode_(const string_view_t& color_code);
91 void print_range_(const memory_buf_t& formatted, size_t start, size_t end);
92 static std::string to_string_(const string_view_t& sv);
93 };
94
95 template <typename ConsoleMutex>
96 class ansicolor_stdout_sink : public ansicolor_sink<ConsoleMutex>
97 {
98 public:
100 };
101
102 template <typename ConsoleMutex>
103 class ansicolor_stderr_sink : public ansicolor_sink<ConsoleMutex>
104 {
105 public:
107 };
108
111
114
115 } // namespace sinks
116} // namespace spdlog
117
118#ifdef SPDLOG_HEADER_ONLY
119#include "ansicolor_sink-inl.h"
120#endif
Definition ansicolor_sink.h:28
const string_view_t green
Definition ansicolor_sink.h:62
ansicolor_sink(ansicolor_sink &&other)=delete
void set_pattern(const std::string &pattern) final
Definition ansicolor_sink-inl.h:76
static std::string to_string_(const string_view_t &sv)
Definition ansicolor_sink-inl.h:127
ansicolor_sink & operator=(ansicolor_sink &&other)=delete
const string_view_t blue
Definition ansicolor_sink.h:64
const string_view_t blink
Definition ansicolor_sink.h:54
const string_view_t red_bold
Definition ansicolor_sink.h:81
const string_view_t red
Definition ansicolor_sink.h:61
void set_color(level::level_enum color_level, string_view_t color)
Definition ansicolor_sink-inl.h:34
const string_view_t bold_on_red
Definition ansicolor_sink.h:82
void set_formatter(std::unique_ptr< spdlog::formatter > sink_formatter) override
Definition ansicolor_sink-inl.h:83
const string_view_t concealed
Definition ansicolor_sink.h:56
const string_view_t on_cyan
Definition ansicolor_sink.h:76
const string_view_t on_magenta
Definition ansicolor_sink.h:75
bool should_color()
Definition ansicolor_sink-inl.h:90
bool should_do_colors_
Definition ansicolor_sink.h:87
std::array< std::string, level::n_levels > colors_
Definition ansicolor_sink.h:89
ansicolor_sink(const ansicolor_sink &other)=delete
const string_view_t reverse
Definition ansicolor_sink.h:55
const string_view_t bold
Definition ansicolor_sink.h:51
const string_view_t dark
Definition ansicolor_sink.h:52
const string_view_t on_white
Definition ansicolor_sink.h:77
const string_view_t black
Definition ansicolor_sink.h:60
const string_view_t cyan
Definition ansicolor_sink.h:66
void set_color_mode(color_mode mode)
Definition ansicolor_sink-inl.h:96
const string_view_t on_green
Definition ansicolor_sink.h:72
const string_view_t underline
Definition ansicolor_sink.h:53
const string_view_t yellow
Definition ansicolor_sink.h:63
const string_view_t on_red
Definition ansicolor_sink.h:71
const string_view_t on_blue
Definition ansicolor_sink.h:74
typename ConsoleMutex::mutex_t mutex_t
Definition ansicolor_sink.h:30
const string_view_t clear_line
Definition ansicolor_sink.h:57
const string_view_t white
Definition ansicolor_sink.h:67
const string_view_t yellow_bold
Bold colors.
Definition ansicolor_sink.h:80
const string_view_t magenta
Definition ansicolor_sink.h:65
void flush() override
Definition ansicolor_sink-inl.h:69
std::unique_ptr< spdlog::formatter > formatter_
Definition ansicolor_sink.h:88
FILE * target_file_
Definition ansicolor_sink.h:85
const string_view_t reset
Definition ansicolor_sink.h:50
mutex_t & mutex_
Definition ansicolor_sink.h:86
void log(const details::log_msg &msg) override
Definition ansicolor_sink-inl.h:41
const string_view_t on_black
Background colors.
Definition ansicolor_sink.h:70
const string_view_t on_yellow
Definition ansicolor_sink.h:73
~ansicolor_sink() override=default
ansicolor_sink & operator=(const ansicolor_sink &other)=delete
void print_ccode_(const string_view_t &color_code)
Definition ansicolor_sink-inl.h:115
void print_range_(const memory_buf_t &formatted, size_t start, size_t end)
Definition ansicolor_sink-inl.h:121
Definition ansicolor_sink.h:104
Definition ansicolor_sink.h:97
Definition sink.h:15
level_enum
Definition common.h:233
ansicolor_stdout_sink< details::console_mutex > ansicolor_stdout_sink_mt
Definition ansicolor_sink.h:109
ansicolor_stderr_sink< details::console_mutex > ansicolor_stderr_sink_mt
Definition ansicolor_sink.h:112
ansicolor_stderr_sink< details::console_nullmutex > ansicolor_stderr_sink_st
Definition ansicolor_sink.h:113
ansicolor_stdout_sink< details::console_nullmutex > ansicolor_stdout_sink_st
Definition ansicolor_sink.h:110
Definition async.h:26
fmt::basic_string_view< char > string_view_t
Definition common.h:172
color_mode
Definition common.h:278
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:173
Definition Bitmap.h:10
Definition log_msg.h:14