clutchlog 0.17
t-extra.cpp
1#include <iostream>
2
3#include "../clutchlog/clutchlog.h"
4
5void dump_data()
6{
7 CLUTCHLOG(progress, "Dump parsed data...");
8 CLUTCHLOG(debug, "Write in `data_dump.csv`");
9 CLUTCHLOG(debug, "Data frame size: " << 0 << "x" << "150");
10 CLUTCHLOG(xdebug, "Resolution: " << 0);
11}
12
13void reset()
14{
15 CLUTCHLOG(progress, "Reset data structures...");
16 CLUTCHLOG(debug, "OK");
17 CLUTCHLOG(info, "Reset functors...");
18 CLUTCHLOG(critical, "Impossible to reset, I cannot recover.");
19 dump_data();
20}
21
22void process()
23{
24 CLUTCHLOG(note, "Filling up data of size: " << 0);
25 CLUTCHLOG(error, "Cannot parse input, I will reset stuff.");
26 reset();
27 CLUTCHLOG(xdebug, "Last seen state: " << 0);
28}
29
30void init_data()
31{
32 CLUTCHLOG(debug, "Data frame size: " << 2 << "x" << "150");
33 CLUTCHLOG(xdebug, "Resolution: " << 0.001);
34 CLUTCHLOG(warning, "Input height < " << 3);
35}
36
37void init_func()
38{
39 CLUTCHLOG(progress, "Allocate memory...");
40 CLUTCHLOG(warning, "Dimension: " << 12);
41 CLUTCHLOG(debug, "OK");
42}
43
44void init()
45{
46 CLUTCHLOG(progress, "Initialize data structures...");
47 init_data();
48 CLUTCHLOG(debug, "OK");
49 CLUTCHLOG(progress, "Initialize functors...");
50 init_func();
51 CLUTCHLOG(debug, "OK");
52 CLUTCHLOG(progress, "Process...");
53 process();
54 CLUTCHLOG(debug, "OK");
55}
56
57int main(const int argc, char* argv[])
58{
59 using level = clutchlog::level;
60 using fmt = clutchlog::fmt;
61 using fg = clutchlog::fmt::fg;
62 using bg = clutchlog::fmt::bg;
63 using typo = clutchlog::fmt::typo;
64
65 auto& log = clutchlog::logger();
66
67 log.style(level::critical, 197);
68 log.style(level::error, 202);
69 log.style(level::warning, 208);
70 log.style(level::progress, 34);
71 log.style(level::note, 35);
72 log.style(level::info, 36);
73 log.style(level::debug, 39);
74 log.style(level::xdebug, 45);
75 std::ostringstream format;
76 fmt reset(typo::reset);
77 fmt discreet(fg::black);
78 fmt bold(fmt::typo::bold);
79
80 log.depth_mark("| ");
81 log.hfill_mark('-');
82
83 const short dark = 238;
84 const short lite = 245;
85
86 std::vector<clutchlog::fmt> greys{ fmt(15) };
87 for(unsigned short i=255; i>231; i-=3) {
88 greys.push_back( fmt(i) );
89 }
90 log.depth_styles(greys);
91
92 format
93 << fmt(dark,lite) << "{name}"
94 << fmt(fg::none,lite,typo::inverse) << "{level_fmt}"
95 << fmt(fg::none,bg::black,typo::inverse) << "{level_fmt}" << " {level_short} " << reset
96 << "{level_fmt} " << reset
97 << fmt(dark,bg::none, typo::bold) << "{depth_marks}" << reset
98 // << "{funchash_fmt}"
99 << "{level_fmt}"
100 << bold("{msg}")
101 // << discreet(" {hfill} ")
102 << fmt(dark,bg::none) << " ·" << ""
103 << fmt(fg::none,dark) << "{funchash_fmt}-{hfill}"
104 << fmt(fg::none,dark) << " {funchash_fmt}{func} "
105 << fmt(lite,dark) << ""
106 // << fmt(dark,lite) << "{filehash_fmt}{file}" << reset
107 << fmt(dark,lite) << "{file}" << reset
108 << fmt(dark,lite) << ""
109 << fmt(lite,dark) << "{line}" << reset
110 << "\n";
111 log.format(format.str());
112
113 log.out(std::clog);
114 log.strip_calls(4);
115 log.filename(clutchlog::filename::dirstem);
116
117 if(argc <= 2) {
118 CLUTCHLOG(warning, "Log level not indicated, will default to xdebug");
119 log.threshold(level::xdebug);
120 } else {
121 try {
122 log.threshold(log.level_of(argv[1]));
123 } catch(std::out_of_range& err) {
124 CLUTCHLOG(critical,err.what());
125 exit(100);
126 }
127 }
128
129 CLUTCHLOG(progress,"Start analysis");
130 init();
131 CLUTCHLOG(progress,"I have stopped");
132}
133
Color and style formatter for ANSI terminal escape sequences.
Definition: clutchlog.h:380
typo
Typographic style codes.
Definition: clutchlog.h:393
level
Available log levels.
Definition: clutchlog.h:314
static clutchlog & logger()
Get the logger instance.
Definition: clutchlog.h:307
#define CLUTCHLOG(LEVEL, WHAT)
Log a message at the given level.
Definition: clutchlog.h:99
bg
Background color codes.
Definition: clutchlog.h:425
fg
Foreground color codes.
Definition: clutchlog.h:404