clutchlog  0.14
t-demo-extravagant.cpp
1 #include <iostream>
2 
3 #include "../clutchlog/clutchlog.h"
4 
5 void 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 
13 void 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 
22 void 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 
30 void 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 
37 void init_func()
38 {
39  CLUTCHLOG(progress, "Allocate memory...");
40  CLUTCHLOG(warning, "Dimension: " << 12);
41  CLUTCHLOG(debug, "OK");
42 }
43 
44 void 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 
57 int 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_min(400);
82  log.hfill_max(500);
83  log.hfill_mark('-');
84 
85  const short dark = 238;
86  const short lite = 250;
87 
88  format
89  << fmt(dark,lite) << "{name}"
90  << fmt(lite,dark) << ""
91  << fmt(fg::none,dark) << "{level_fmt}" << " {level_short} " << reset
92  << fmt(dark,bg::none) << "" << reset
93  << fmt(dark,bg::none) << "{depth_marks}" << reset
94  << "{level_fmt}"
95  << bold("{msg}")
96  << discreet(" {hfill} ")
97  << fmt(dark,bg::none) << ""
98  << fmt(fg::none,dark) << "{level_fmt} {func} "
99  << fmt(lite,dark) << ""
100  << fmt(dark,lite) << "{file}" << reset
101  << fmt(dark,lite) << ""
102  << fmt(lite,dark) << "{line}" << reset
103  << "\n";
104  log.format(format.str());
105 
106  log.out(std::clog);
107  log.strip_calls(4);
108 
109  if(argc <= 2) {
110  CLUTCHLOG(warning, "Log level not indicated, will default to xdebug");
111  log.threshold(level::xdebug);
112  } else {
113  try {
114  log.threshold(log.level_of(argv[1]));
115  } catch(std::out_of_range& err) {
116  CLUTCHLOG(critical,err.what());
117  exit(100);
118  }
119  }
120 
121  CLUTCHLOG(progress,"Start analysis");
122  init();
123  CLUTCHLOG(progress,"I have stopped");
124 }
125 
clutchlog::level
level
Available log levels.
Definition: clutchlog.h:303
clutchlog::logger
static clutchlog & logger()
Get the logger instance.
Definition: clutchlog.h:296
clutchlog::fmt
Color and style formatter for ANSI terminal escape sequences.
Definition: clutchlog.h:366
clutchlog::fmt::bg
bg
Background color codes.
Definition: clutchlog.h:411
CLUTCHLOG
#define CLUTCHLOG(LEVEL, WHAT)
Log a message at the given level.
Definition: clutchlog.h:81
clutchlog::fmt::typo
typo
Typographic style codes.
Definition: clutchlog.h:379
clutchlog::fmt::fg
fg
Foreground color codes.
Definition: clutchlog.h:390