 |
clutchlog
0.16
|
Go to the documentation of this file.
9 #include <experimental/filesystem>
10 namespace fs = std::experimental::filesystem;
13 namespace fs = std::filesystem;
27 #if __has_include(<execinfo.h>) && __has_include(<stdlib.h>) && __has_include(<libgen.h>)
31 #define CLUTCHLOG_HAVE_UNIX_SYSINFO 1
33 #define CLUTCHLOG_HAVE_UNIX_SYSINFO 0
37 #if __has_include(<sys/ioctl.h>) && __has_include(<stdio.h>) && __has_include(<unistd.h>)
38 #include <sys/ioctl.h>
41 #define CLUTCHLOG_HAVE_UNIX_SYSIOCTL 1
43 #define CLUTCHLOG_HAVE_UNIX_SYSIOCTL 0
50 #ifndef WITH_CLUTCHLOG
52 #define WITH_CLUTCHLOG
65 #ifndef CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG
66 #define CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG clutchlog::level::progress
68 #endif // CLUTCHLOG_DEFAULT_DEPTH_BUILT
76 #define CLUTCHLOC __FILE__, __FUNCTION__, __LINE__
81 #define CLUTCHLOGD( LEVEL, WHAT, DEPTH_DELTA ) do { \
82 auto& clutchlog__logger = clutchlog::logger(); \
83 std::ostringstream clutchlog__msg ; clutchlog__msg << WHAT; \
84 clutchlog__logger.log(clutchlog::level::LEVEL, clutchlog__msg.str(), CLUTCHLOC, DEPTH_DELTA); \
86 #else // not Debug build.
87 #define CLUTCHLOGD( LEVEL, WHAT, DEPTH_DELTA ) do { \
88 if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \
89 auto& clutchlog__logger = clutchlog::logger(); \
90 std::ostringstream clutchlog__msg ; clutchlog__msg << WHAT; \
91 clutchlog__logger.log(clutchlog::level::LEVEL, clutchlog__msg.str(), CLUTCHLOC, DEPTH_DELTA); \
98 #define CLUTCHLOG( LEVEL, WHAT ) \
99 CLUTCHLOGD(LEVEL, WHAT, 0)
100 #else // not Debug build.
101 #define CLUTCHLOG( LEVEL, WHAT ) \
102 CLUTCHLOGD(LEVEL, WHAT, 0)
107 #define CLUTCHDUMP( LEVEL, CONTAINER, FILENAME ) do { \
108 auto& clutchlog__logger = clutchlog::logger(); \
109 clutchlog__logger.dump(clutchlog::level::LEVEL, std::begin(CONTAINER), std::end(CONTAINER), \
110 CLUTCHLOC, FILENAME, CLUTCHDUMP_DEFAULT_SEP); \
112 #else // not Debug build.
113 #define CLUTCHDUMP( LEVEL, CONTAINER, FILENAME ) do { \
114 if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \
115 auto& clutchlog__logger = clutchlog::logger(); \
116 clutchlog__logger.dump(clutchlog::level::LEVEL, std::begin(CONTAINER), std::end(CONTAINER), \
117 CLUTCHLOC, FILENAME, CLUTCHDUMP_DEFAULT_SEP); \
124 #define CLUTCHFUNC( LEVEL, FUNC, ... ) do { \
125 auto& clutchlog__logger = clutchlog::logger(); \
126 clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
127 if(clutchlog__scope.matches) { \
131 #else // not Debug build.
132 #define CLUTCHFUNC( LEVEL, FUNC, ... ) do { \
133 if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \
134 auto& clutchlog__logger = clutchlog::logger(); \
135 clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
136 if(clutchlog__scope.matches) { \
145 #define CLUTCHCODE( LEVEL, ... ) do { \
146 auto& clutchlog__logger = clutchlog::logger(); \
147 clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
148 if(clutchlog__scope.matches) { \
152 #else // not Debug build.
153 #define CLUTCHCODE( LEVEL, CODE ) do { \
154 if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \
155 auto& clutchlog__logger = clutchlog::logger(); \
156 clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
157 if(clutchlog__scope.matches) { \
166 #else // not WITH_CLUTCHLOG
168 #define CLUTCHLOG( LEVEL, WHAT ) do {} while(0)
169 #define CLUTCHLOGD( LEVEL, WHAT, DEPTH_DELTA ) do {} while(0)
170 #define CLUTCHDUMP( LEVEL, CONTAINER, FILENAME ) do {} while(0)
171 #define CLUTCHFUNC( LEVEL, FUNC, ... ) do {} while(0)
172 #define CLUTCHCODE( LEVEL, CODE ) do {} while(0)
173 #endif // WITH_CLUTCHLOG
179 #ifdef WITH_CLUTCHLOG
196 #ifndef CLUTCHLOG_DEFAULT_FORMAT
197 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1 // Enables: name, depth and depth_marks
199 #if CLUTCHLOG_HAVE_UNIX_SYSIOCTL == 1 // Enables: hfill
200 #define CLUTCHLOG_DEFAULT_FORMAT "[{name}] {level_letter}:{depth_marks} {msg} {hfill} {func} @ {file}:{line}\n"
202 #define CLUTCHLOG_DEFAULT_FORMAT "[{name}] {level_letter}:{depth_marks} {msg}\t\t\t\t\t{func} @ {file}:{line}\n"
205 #if CLUTCHLOG_HAVE_UNIX_SYSIOCTL == 1
206 #define CLUTCHLOG_DEFAULT_FORMAT "{level_letter} {msg} {hfill} {func} @ {file}:{line}\n"
208 #define CLUTCHLOG_DEFAULT_FORMAT "{level_letter} {msg}\t\t\t\t\t{func} @ {file}:{line}\n"
213 #ifndef CLUTCHLOG_DEFAULT_FORMAT
214 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
216 #define CLUTCHLOG_DEFAULT_FORMAT "[{name}] {level_letter}:{depth_marks} {msg} {hfill} {func}\n"
218 #define CLUTCHLOG_DEFAULT_FORMAT "{level_letter} {msg}\t\t\t\t\t{func}\n"
226 #ifndef CLUTCHDUMP_DEFAULT_FORMAT
227 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
229 #define CLUTCHDUMP_DEFAULT_FORMAT "# [{name}] {level} in {func} (at depth {depth}) @ {file}:{line}"
231 #define CLUTCHDUMP_DEFAULT_FORMAT "# {level} in {func} @ {file}:{line}"
233 #endif // CLUTCHDUMP_DEFAULT_FORMAT
235 #ifndef CLUTCHDUMP_DEFAULT_FORMAT
236 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
238 #define CLUTCHDUMP_DEFAULT_FORMAT "# [{name}] {level} in {func} (at depth {depth})"
240 #define CLUTCHDUMP_DEFAULT_FORMAT "# {level} in {func}"
242 #endif // CLUTCHDUMP_DEFAULT_FORMAT
247 #ifndef CLUTCHDUMP_DEFAULT_SEP
248 #define CLUTCHDUMP_DEFAULT_SEP "\n"
250 #endif // CLUTCHDUMP_DEFAULT_SEP
254 #ifndef CLUTCHLOG_DEFAULT_DEPTH_MARK
255 #define CLUTCHLOG_DEFAULT_DEPTH_MARK ">"
257 #endif // CLUTCHLOG_DEFAULT_DEPTH_MARK
261 #ifndef CLUTCHLOG_STRIP_CALLS
262 #define CLUTCHLOG_STRIP_CALLS 5
264 #endif // CLUTCHLOG_STRIP_CALLS
268 #ifndef CLUTCHLOG_DEFAULT_HFILL_MARK
269 #define CLUTCHLOG_DEFAULT_HFILL_MARK '.'
271 #endif // CLUTCHLOG_DEFAULT_HFILL_MARK
276 #if CLUTCHLOG_HAVE_UNIX_SYSIOCTL == 1
277 #ifndef CLUTCHLOG_DEFAULT_HFILL_MAX
278 #define CLUTCHLOG_DEFAULT_HFILL_MAX 300
280 #ifndef CLUTCHLOG_DEFAULT_HFILL_MIN
281 #define CLUTCHLOG_DEFAULT_HFILL_MIN 150
313 enum level {critical=0, error=1, warning=2, progress=3, note=4, info=5, debug=6, xdebug=7};
316 enum filename {path, base, dir, dirbase, stem, dirstem};
438 bright_magenta = 105,
446 friend std::ostream&
operator<<(std::ostream& os,
const std::tuple<fg,bg,typo>& fbs)
449 std::vector<short> codes; codes.reserve(3);
450 if(f != fg::none) { codes.push_back(
static_cast<short>(f));}
451 if(b != bg::none) { codes.push_back(
static_cast<short>(b));}
452 if(s != typo::none) { codes.push_back(
static_cast<short>(s));}
453 if(codes.size() == 0) {
459 for(
size_t i=1; i < codes.size(); ++i) {
460 os <<
";" << codes[i];
470 if(s != typo::none) {
471 os <<
"\033[" <<
static_cast<short>(s) <<
"m";
500 virtual bool is_set()
const = 0;
503 virtual std::ostream&
print_on( std::ostream& os)
const = 0;
509 os <<
"\033[" <<
static_cast<short>(c.
type) <<
";" <<
static_cast<short>(c.mode) <<
";";
605 :
color(
ansi::colors_16M, t),
red(r), green(g), blue(b) {}
616 assert(srgb.size() == 7);
617 if(srgb.size() != 7) {
623 if(srgb.at(0) ==
'#') {
626 std::istringstream(srgb.substr(0+i,2)) >> std::hex >>
red;
627 std::istringstream(srgb.substr(2+i,2)) >> std::hex >> green;
628 std::istringstream(srgb.substr(4+i,2)) >> std::hex >> blue;
630 assert(-1 <=
red and
red <= 255);
631 assert(-1 <= green and green <= 255);
632 assert(-1 <= blue and blue <= 255);
636 bool is_set()
const {
return red > -1 and green > -1 and blue > -1;}
641 os <<
red <<
";" << green <<
";" << blue;
731 fmt(
const short fr,
const short fg,
const short fb,
732 const short gr,
const short gg,
const short gb,
736 const short gr,
const short gg,
const short gb,
739 fmt(
const short fr,
const short fg,
const short fb,
742 fmt(
const short fr,
const short fg,
const short fb,
746 fmt(
const std::string& f,
const std::string& b,
typo s = typo::none)
748 fmt(
fg,
const std::string& b,
typo s = typo::none)
750 fmt(
const std::string& f,
bg,
typo s = typo::none)
752 fmt(
const std::string& f,
typo s = typo::none)
810 std::ostringstream os;
812 fmt reset(fmt::typo::reset);
822 std::ostringstream os;
827 static fmt hash(
const std::string&
str,
const std::vector<fmt> domain = {})
829 size_t h = std::hash<std::string>{}(
str);
830 if(domain.size() == 0) {
831 return fmt(
static_cast<short>(h % 256));
833 return fmt(domain[h % domain.size()]);
845 void operator=(
clutchlog const&) =
delete;
852 {level::critical,
"Critical"},
853 {level::error ,
"Error"},
854 {level::warning ,
"Warning"},
855 {level::progress,
"Progress"},
856 {level::note ,
"Note"},
857 {level::info ,
"Info"},
858 {level::debug ,
"Debug"},
859 {level::xdebug ,
"XDebug"}
862 {level::critical,
"Crit"},
863 {level::error ,
"Erro"},
864 {level::warning ,
"Warn"},
865 {level::progress,
"Prog"},
866 {level::note ,
"Note"},
867 {level::info ,
"Info"},
868 {level::debug ,
"Dbug"},
869 {level::xdebug ,
"XDbg"}
872 {level::critical,fmt(fmt::fg::red, fmt::typo::underline)},
873 {level::error ,fmt(fmt::fg::red, fmt::typo::bold)},
874 {level::warning ,fmt(fmt::fg::magenta, fmt::typo::bold)},
875 {level::progress,fmt()},
876 {level::note ,fmt()},
877 {level::info ,fmt()},
878 {level::debug ,fmt()},
879 {level::xdebug ,fmt()}
883 #if CLUTCHLOG_HAVE_UNIX_SYSIOCTL
885 _hfill_fmt(fmt::fg::none),
890 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
891 _depth(std::numeric_limits<size_t>::max() -
_strip_calls),
908 #if CLUTCHLOG_HAVE_UNIX_SYSIOCTL
910 ioctl(STDERR_FILENO, TIOCGWINSZ, &w);
930 #if CLUTCHLOG_HAVE_UNIX_SYSIOCTL
942 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
946 std::string _depth_mark;
962 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
964 static const size_t _max_buffer = 4096;
966 std::vector<fmt> _depth_fmts;
969 #if CLUTCHLOG_HAVE_UNIX_SYSIOCTL
998 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
999 void depth(
size_t d) {_depth = d;}
1002 size_t depth()
const {
return _depth;}
1005 void depth_mark(
const std::string mark) {_depth_mark = mark;}
1007 std::string depth_mark()
const {
return _depth_mark;}
1014 #if CLUTCHLOG_HAVE_UNIX_SYSIOCTL == 1
1015 void hfill_mark(
const char mark) {_hfill_char = mark;}
1018 char hfill_mark()
const {
return _hfill_char;}
1020 void hfill_style(fmt
style) {_hfill_fmt =
style;}
1025 template<
class ... FMT>
1026 void hfill_style(FMT... styles) { this->hfill_style(fmt(styles...)); }
1028 fmt hfill_style()
const {
return _hfill_fmt;}
1030 void hfill_max(
const size_t nmax) {_hfill_max = nmax;}
1032 size_t hfill_max() {
return _hfill_max;}
1034 void hfill_min(
const size_t nmin) {_hfill_min = nmin;}
1036 size_t hfill_min() {
return _hfill_min;}
1081 return ilevel->second;
1083 throw std::out_of_range(
"'" + name +
"' is not a valid log level name");
1096 const std::string& in_file,
1097 const std::string& in_function=
".*",
1098 const std::string& in_line=
".*"
1110 template<
class ... FMT>
1133 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
1154 const std::string&
file,
1155 const std::string&
func,
1163 scope.stage = stage;
1164 if(not (scope.stage <=
_stage)) {
1169 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
1173 void *buffer[_max_buffer];
1174 stack_depth = backtrace(buffer, _max_buffer);
1175 scope.depth = stack_depth;
1184 std::ostringstream sline; sline <<
line;
1188 and std::regex_search(sline.str(),
_in_line);
1191 scope.matches = scope.there;
1204 const std::string& form,
1205 const std::string& mark,
1206 const std::string& tag
1263 const std::regex re(mark);
1264 return std::regex_replace(form, re, tag);
1269 const std::string& form,
1270 const std::string& mark,
1274 std::ostringstream stag; stag << tag;
1275 return replace(form, mark, stag.str());
1281 const std::string& what,
1283 const std::string& name,
1286 const std::string&
file,
1287 const std::string&
func,
1295 row =
replace(row,
"\\{msg\\}", what);
1297 const std::filesystem::path filepath(
file);
1298 assert(filepath.is_absolute());
1300 std::filesystem::path::iterator ip = filepath.end();
1301 std::advance(ip, -2);
1303 case filename::base:
1304 filename = filepath.filename().string();
1309 case filename::dirbase:
1310 filename = (*ip / filepath.filename()).
string();
1312 case filename::stem:
1313 filename = filepath.stem().string();
1315 case filename::dirstem:
1316 filename = (*ip / filepath.stem()).
string();
1318 case filename::path:
1330 std::string letter(1,
_level_word.at(stage).at(0));
1331 row =
replace(row,
"\\{level_letter\\}", letter);
1334 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
1336 row =
replace(row,
"\\{name\\}", name);
1337 row =
replace(row,
"\\{depth\\}", actual_depth);
1339 if(_depth_fmts.size() == 0) {
1340 row =
replace(row,
"\\{depth_fmt\\}",
fmt(actual_depth % 256).str() );
1342 std::ostringstream chevrons;
1343 for(
size_t i = 0; i < actual_depth; ++i) {
1344 chevrons << _depth_mark;
1346 row =
replace(row,
"\\{depth_marks\\}", chevrons.str());
1349 row =
replace(row,
"\\{depth_fmt\\}",
1350 _depth_fmts[std::min(actual_depth,_depth_fmts.size()-1)].str() );
1352 std::ostringstream chevrons;
1353 for(
size_t i = 0; i < actual_depth; ++i) {
1354 chevrons << _depth_fmts[std::min(i+1,_depth_fmts.size()-1)].str()
1357 row =
replace(row,
"\\{depth_marks\\}", chevrons.str());
1364 #if CLUTCHLOG_HAVE_UNIX_SYSIOCTL
1366 const std::string raw_row =
replace(row,
"\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]",
"");
1367 const std::string hfill_tag =
"{hfill}";
1368 const size_t hfill_pos = row.find(hfill_tag);
1369 const size_t raw_hfill_pos = raw_row.find(hfill_tag);
1370 const size_t nb_columns = std::max(std::min((
size_t)_nb_columns, _hfill_max), _hfill_min);
1371 if(hfill_pos != std::string::npos) {
1372 assert(raw_hfill_pos != std::string::npos);
1373 if(nb_columns > 0) {
1374 const size_t left_len = raw_hfill_pos;
1375 const size_t right_len = raw_row.size() - raw_hfill_pos - hfill_tag.size();
1376 if(right_len+left_len > nb_columns) {
1378 if(right_len < nb_columns) {
1380 const std::string hfill(std::max((
size_t)0, nb_columns-right_len), _hfill_char);
1381 const std::string hfill_styled = _hfill_fmt(hfill);
1382 row =
replace(row,
"\\{hfill\\}",
"\n"+hfill_styled);
1385 const std::string hfill(1, _hfill_char);
1386 const std::string hfill_styled = _hfill_fmt(hfill);
1387 row =
replace(row,
"\\{hfill\\}",
"\n"+hfill_styled);
1391 const std::string hfill(std::max((
size_t)0, nb_columns - (right_len+left_len)), _hfill_char);
1392 const std::string hfill_styled = _hfill_fmt(hfill);
1393 row =
replace(row,
"\\{hfill\\}", hfill_styled);
1397 const std::string hfill(1, _hfill_char);
1398 const std::string hfill_styled = _hfill_fmt(hfill);
1399 row =
replace(row,
"\\{hfill\\}", hfill_styled);
1404 const std::string hfill(1, _hfill_char);
1405 const std::string hfill_styled = _hfill_fmt(hfill);
1406 row =
replace(row,
"\\{hfill\\}", hfill_styled);
1414 const std::string& what,
1415 const std::string&
file,
const std::string&
func,
const size_t line,
1416 const size_t depth_delta = 0
1422 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
1425 line, scope.depth + depth_delta );
1439 const In container_begin,
const In container_end,
1440 const std::string&
file,
const std::string&
func,
const size_t line,
1441 const std::string& filename_template =
"dump_{n}.dat",
1448 const std::string tag =
"\\{n\\}";
1449 const std::regex re(tag);
1450 std::string outfile =
"";
1453 if(std::regex_search(filename_template, re)) {
1457 outfile =
replace(filename_template, tag, n);
1459 }
while( fs::exists( outfile ) );
1463 outfile = filename_template;
1466 std::ofstream fd(outfile);
1469 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
1472 line, scope.depth );
1481 std::copy(container_begin, container_end,
1482 std::ostream_iterator<typename In::value_type>(fd, sep.c_str()));
1493 #else // not WITH_CLUTCHLOG
1502 #pragma GCC diagnostic push
1503 #pragma GCC diagnostic ignored "-Wreturn-type"
1508 enum level {critical=0, error=1, warning=2, progress=3, note=4, info=5, debug=6, xdebug=7};
1509 enum filename {path, base, dir, dirbase, stem, dirstem};
1513 enum class typo { reset, bold, underline, inverse, none}
style;
1514 enum class fg { black, red, green, yellow, blue, magenta, cyan, white, bright_black, bright_red, bright_green, bright_yellow, bright_blue, bright_magenta, bright_cyan, bright_white, none}
fore;
1515 enum class bg { black, red, green, yellow, blue, magenta, cyan, white, bright_black, bright_red, bright_green, bright_yellow, bright_blue, bright_magenta, bright_cyan, bright_white, none }
back;
1517 friend std::ostream&
operator<<(std::ostream&,
const std::tuple<fg,bg,typo>&) {}
1524 virtual bool is_set()
const = 0;
1525 virtual std::ostream&
print_on( std::ostream&)
const = 0;
1528 struct color_256 :
public color {
1533 std::ostream&
print_on( std::ostream&)
const {}
1535 struct fg_256 :
public color_256 {
1540 struct bg_256 :
public color_256 {
1545 struct color_16M :
public color {
1546 short red, green, blue;
1550 bool is_set()
const {
return red > -1 and green > -1 and blue > -1;}
1551 std::ostream&
print_on( std::ostream&)
const {}
1553 struct fg_16M :
public color_16M {
1559 struct bg_16M :
public color_16M {
1576 fmt(
const short fr,
const short fg,
const short fb,
1577 const short gr,
const short gg,
const short gb,
1578 typo s = typo::none)
1581 const short gr,
const short gg,
const short gb,
1582 typo s = typo::none)
1584 fmt(
const short fr,
const short fg,
const short fb,
1587 fmt(
const short fr,
const short fg,
const short fb,
1588 typo s = typo::none)
1591 fmt(
const std::string& f,
const std::string& b,
typo s = typo::none)
1593 fmt(
fg,
const std::string& b,
typo s = typo::none)
1595 fmt(
const std::string& f,
bg,
typo s = typo::none)
1597 fmt(
const std::string& f,
typo s = typo::none)
1600 std::ostream&
print_on( std::ostream&)
const {}
1602 friend std::ostream&
operator<<(std::ostream&,
const fmt&) {}
1603 std::string
operator()(
const std::string&)
const {}
1604 std::string
str()
const {}
1605 static fmt hash(
const std::string&,
const std::vector<fmt>) {}
1609 void operator=(
clutchlog const&) =
delete;
1622 void format(
const std::string&) {}
1623 std::string
format()
const {}
1628 void out(std::ostream&) {}
1629 std::ostream&
out() {}
1631 #if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
1632 void depth(
size_t) {}
1633 size_t depth()
const {}
1635 void depth_mark(
const std::string) {}
1636 std::string depth_mark()
const {}
1637 void strip_calls(
const size_t) {}
1638 size_t strip_calls()
const {}
1640 #if CLUTCHLOG_HAVE_UNIX_SYSIOCTL == 1
1641 void hfill_mark(
const char) {}
1642 char hfill_mark()
const {}
1643 void hfill_fmt(fmt) {}
1644 fmt hfill_fmt()
const {}
1645 void hfill_min(
const size_t) {}
1646 size_t hfill_min() {}
1647 void hfill_max(
const size_t) {}
1648 size_t hfill_max() {}
1657 const std::map<std::string,level>
levels()
const {}
1660 void file(std::string) {}
1661 void func(std::string) {}
1662 void line(std::string) {}
1664 #pragma GCC diagnostic push
1665 #pragma GCC diagnostic ignored "-Wunused-parameter"
1668 const std::string& in_function=
".*",
1669 const std::string& in_line=
".*"
1672 #pragma GCC diagnostic pop
1673 template<
class ... FMT>
1713 const std::string&,
const std::string&,
size_t
1721 const std::string&,
const std::string&,
size_t,
1727 #pragma GCC diagnostic pop
1728 #endif // WITH_CLUTCHLOG
1730 #endif // CLUTCHLOG_H
friend std::ostream & operator<<(std::ostream &os, const std::tuple< fg, bg, typo > &fbs)
Output stream operator for a 3-tuple of 16-colors mode tags.
static std::string default_depth_mark
Default mark for stack depth.
std::string _format_log
Current format of the standard output.
color_16M(ground t, const std::string &srgb)
Hex triplet string constructor.
void dump(const level &stage, const In container_begin, const In container_end, const std::string &file, const std::string &func, const size_t line, const std::string &filename_template="dump_{n}.dat", const std::string sep=dump_default_sep) const
Dump a serializable container after a comment line with log information.
void depth_styles(std::vector< fmt > styles)
Set the styles for value-dependant depth formatting.
std::map< level, fmt > _level_fmt
Dictionary of level identifier to their format.
enum clutchlog::fmt::bg back
Background color.
std::vector< fmt > _funchash_fmts
List of candidate format objects for value-dependant function name styling.
std::string str() const
Return the formatting code as a string.
Foreground in 256-colors mode.
void line(std::string line)
Set the regular expression filtering the line location.
friend std::ostream & operator<<(std::ostream &os, const color &c)
Print the actually encoded escaped color sequence on the given stream.
friend std::ostream & operator<<(std::ostream &os, const typo &s)
Output stream operator for a typo tag alone, in 16-colors mode.
static std::string dump_default_format
Default format of the comment line in file dump.
filename _filename
Filename rendering method.
void out(std::ostream &out)
Set the output stream on which to print.
bool is_set() const
Returns true if the underying representation encodes an existing color.
fg_16M(const fg &)
Conversion constructor from 16-colors mode.
static std::string dump_default_sep
Default item separator for dump.
std::string format(std::string row, const std::string &what, const level &stage, const std::string &file, const std::string &func, const size_t line) const
Substitute all tags in the format string with the corresponding information and apply the style corre...
Background in 256-colors mode.
#define CLUTCHLOG_DEFAULT_DEPTH_MARK
Compile-time default mark for stack depth.
static unsigned int default_strip_calls
Number of call stack levels to remove from depth display by default.
static size_t default_hfill_min
Default minimum width (number of characters) at which to fill for right-aligning the right part of me...
std::string replace(const std::string &form, const std::string &mark, const std::string &tag) const
Replace mark by tag in form.
color_256(ground t)
Constructor.
clutchlog::fmt::bg_16M back_16M
Current background in 16M-colors mode.
Interface class for colors representation.
@ colors_16
16 colors mode.
background in 256-colors mode.
static char default_hfill_char
Default character used as a filling for right-align the right part of messages with "{hfill}".
bool matches
Everything is compatible.
enum clutchlog::fmt::typo style
Typographic style.
Abstract base class for 16M colors objects (24-bits ANSI).
fg_256(const fg &)
Conversion constructor from 16-colors mode.
void format_comment(const std::string &format)
Set the template string for dumps.
bg_16M(const std::string &srgb)
Hex triplet string constructor.
void file(std::string file)
Set the regular expression filtering the file location.
scope_t locate(const level &stage, const std::string &file, const std::string &func, const size_t line) const
Gather information on the current location of the call.
clutchlog::fmt::fg_16M fore_16M
Current foreground in 16M-colors mode.
Abstract base class for 256 colors objects (8-bits ANSI).
fmt()
Empty constructor, only useful for a no-op formatter.
void style(level stage, fmt style)
Set the style (color and typo) of the given log level, passing a fmt instance.
void threshold(level l)
Set the log level (below which logs are not printed) with an identifier.
level threshold() const
Get the log level below which logs are not printed.
virtual bool is_set() const =0
Should return true if the underying representation encodes an existing color.
std::map< level, std::string > _level_short
dictionary of level identifier to their 4-letters representation.
level
Available log levels.
color_256(ground t, const short i)
Constructor.
std::ostream & print_on(std::ostream &os) const
Print the color index on the given stream.
color_16M(ground t)
Constructor.
static size_t default_hfill_max
Default maximum width (number of characters) for which to fill for right-aligning the right part of m...
void funchash_styles(std::vector< fmt > styles)
Set the candidate styles for value-dependant function name formatting.
std::regex _in_func
Current function location filter.
static std::string default_format
Default format of the messages.
bg_16M(short r, short g, short b)
Numeric triplet constructor.
static clutchlog & logger()
Get the logger instance.
Foreground in 256-colors mode.
clutchlog::fmt::fg_256 fore_256
Current foreground in 256-colors mode.
enum clutchlog::fmt::fg fore
Foreground color.
void filehash_styles(std::vector< fmt > styles)
Set the candidate styles for value-dependant file name formatting.
enum clutchlog::fmt::color::ground type
Type of color (foreground or background).
Color and style formatter for ANSI terminal escape sequences.
short index
The encoded color index in 4-bits ANSI.
bg_256()
Empty constructor: no color.
void func(std::string func)
Set the regular expression filtering the function location.
std::string format() const
Get the template string.
std::regex _in_file
Current file location filter.
void style(level stage, FMT... styles)
Set the style (color and typo) of the given log level.
bg_256(const bg &)
Conversion constructor from 16-colors mode.
fg_16M()
Empty constructor: no color.
level level_of(const std::string name)
Return the log level tag corresponding to the given pre-configured name.
void filename(filename f)
Sets the file naming scheme. */.
const std::map< level, std::string > _level_word
Dictionary of level identifier to their string representation.
std::string operator()(const std::string &msg) const
Format the given string with the currently encoded format.
color_16M(ground t, short r, short g, short b)
Numeric triplet constructor.
std::ostream & print_on(std::ostream &os) const
Print the color RGB triplet on the given stream.
bg
Background color codes.
#define CLUTCHLOG_DEFAULT_FORMAT
Compile-time default format of the messages (debug mode: with absolute location).
std::regex _in_line
Current line location filter.
fg_256(const short f)
Constructor.
@ colors_256
256 colors mode.
enum clutchlog::fmt::ansi mode
Current ANSI color mode.
std::string replace(const std::string &form, const std::string &mark, const size_t tag) const
Replace mark by tag in form, converting tag to its string representation first.
std::string format_comment() const
Get the template string for dumps.
fg_256()
Empty constructor: no color.
@ colors_16M
16 millions ("true") colors mode.
std::string _format_dump
Current format of the file output.
#define CLUTCHDUMP_DEFAULT_SEP
Compile-time default item separator for dump.
bg_256(const short b)
Constructor.
ground
Codes for representing foreground or background.
filename
Available filename rendering methods.
Structure holding a location matching.
#define CLUTCHLOG_DEFAULT_HFILL_MARK
Character used as a filling for right-align the right part of messages with "{hfill}".
std::ostream & print_on(std::ostream &os) const
Print the currently encoded format escape code on the given output stream.
bool is_set() const
Returns true if the underying representation encodes an existing color.
std::ostream * _out
Standard output.
std::ostream & out()
Get the output stream on which to print.
void threshold(const std::string &l)
Set the log level (below which logs are not printed) with a string.
virtual std::ostream & print_on(std::ostream &os) const =0
Should print the underlying representation on the given stream.
const std::map< std::string, level > & levels() const
Get the map of available log levels string representations toward their identifier....
size_t _strip_calls
Current number of call stack levels to remove from depth display.
level stage
Current log level.
bool there
Location is compatible.
fg_16M(const std::string &srgb)
Hex triplet string constructor.
#define CLUTCHLOG_STRIP_CALLS
Compile-time number of call stack levels to remove from depth display by default.
friend std::ostream & operator<<(std::ostream &os, const fmt &fmt)
Output stream overload.
void log(const level &stage, const std::string &what, const std::string &file, const std::string &func, const size_t line, const size_t depth_delta=0) const
Print a log message IF the location matches the given one.
bg_16M(const bg &)
Conversion constructor from 16-colors mode.
bg_16M()
Empty constructor: no color.
std::map< std::string, level > _word_level
Dictionary of level string to their identifier.
level _stage
Current log level.
fmt style(level stage) const
Get the configured fmt instance of the given log level.
typo
Typographic style codes.
void location(const std::string &in_file, const std::string &in_function=".*", const std::string &in_line=".*")
Set the regular expressions filtering the location.
#define CLUTCHLOG_HAVE_UNIX_SYSINFO
True if POSIX headers necessary for stack depth management are available.
std::vector< fmt > _filehash_fmts
List of candidate format objects for value-dependant file name styling.
The single class which holds everything.
ansi
ANSI code configuring the available number of colors.
fg_16M(short r, short g, short b)
Numeric triplet constructor.
fg
Foreground color codes.
short red
The encoded RGB indices.
#define CLUTCHDUMP_DEFAULT_FORMAT
Compile-time default format of the comment line in file dump.
color(ansi a, ground g)
Constructor.
clutchlog::fmt::bg_256 back_256
Current background in 256-colors mode.