clutchlog  0.13
t-demo-extravagant.cpp
1 #include <iostream>
2 
3 #include "../clutchlog/clutchlog.h"
4 
5 void i()
6 {
7  CLUTCHLOG(progress, "Reset data structures...");
8  CLUTCHLOG(debug, "OK");
9  CLUTCHLOG(info, "Reset functors...");
10  CLUTCHLOG(critical, "Impossible to reset, I cannot recover.");
11 }
12 
13 void h()
14 {
15  CLUTCHLOG(note, "Filling up data of size: " << 0);
16  CLUTCHLOG(error, "Cannot parse input, I will reset stuff.");
17  i();
18  CLUTCHLOG(xdebug, "Last seen state: " << 0);
19 }
20 
21 void g()
22 {
23  CLUTCHLOG(warning, "Input size < " << 1);
24  h();
25 }
26 
27 void f()
28 {
29  CLUTCHLOG(progress, "Initialize data structures...");
30  CLUTCHLOG(debug, "OK");
31  CLUTCHLOG(progress, "Initialize functors...");
32  CLUTCHLOG(debug, "OK");
33  g();
34 }
35 
36 int main(const int argc, char* argv[])
37 {
38  using level = clutchlog::level;
39  using fmt = clutchlog::fmt;
40  using fg = clutchlog::fmt::fg;
41  using bg = clutchlog::fmt::bg;
42  using typo = clutchlog::fmt::typo;
43 
44  auto& log = clutchlog::logger();
45 
46  log.style(level::critical, 197);
47  log.style(level::error, 202);
48  log.style(level::warning, 208);
49  log.style(level::progress, 34);
50  log.style(level::note, 35);
51  log.style(level::info, 36);
52  log.style(level::debug, 39);
53  log.style(level::xdebug, 45);
54  std::ostringstream format;
55  fmt reset(typo::reset);
56  fmt discreet(fg::black);
57  fmt bold(fmt::typo::bold);
58 
59  log.depth_mark("| ");
60  log.hfill_min(400);
61  log.hfill_max(500);
62  log.hfill_mark('-');
63 
64  const short dark = 238;
65  const short lite = 250;
66 
67  format
68  << fmt(dark,lite) << "{name}"
69  << fmt(lite,dark) << ""
70  << fmt(fg::none,dark) << "{level_fmt}" << " {level_short} " << reset
71  << fmt(dark,bg::none) << "" << reset
72  << fmt(dark,bg::none) << "{depth_marks}" << reset
73  << "{level_fmt}"
74  << bold("{msg}")
75  << discreet(" {hfill} ")
76  << fmt(dark,bg::none) << ""
77  << fmt(fg::none,dark) << "{level_fmt} {func} "
78  << fmt(lite,dark) << ""
79  << fmt(dark,lite) << "{file}" << reset
80  << fmt(dark,lite) << ""
81  << fmt(lite,dark) << "{line}" << reset
82  << "\n";
83  log.format(format.str());
84 
85  log.out(std::clog);
86  log.strip_calls(4);
87 
88  if(argc <= 2) {
89  CLUTCHLOG(warning, "Log level not indicated, will default to xdebug");
90  log.threshold(level::xdebug);
91  } else {
92  try {
93  log.threshold(log.level_of(argv[1]));
94  } catch(std::out_of_range& err) {
95  CLUTCHLOG(critical,err.what());
96  exit(100);
97  }
98  }
99 
100  CLUTCHLOG(progress,"Start something");
101  f();
102  CLUTCHLOG(progress,"I have stopped");
103 }
104 
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