clutchlog  0.12
t-demo.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(progress, "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  auto& log = clutchlog::logger();
39 
40  log.style(clutchlog::level::critical,
41  clutchlog::fmt::fg::red);
42  log.style(clutchlog::level::error,
43  clutchlog::fmt::fg::red);
44  log.style(clutchlog::level::warning,
45  clutchlog::fmt::fg::magenta);
46  log.style(clutchlog::level::progress,
47  clutchlog::fmt::fg::yellow);
48  log.style(clutchlog::level::note,
49  clutchlog::fmt::fg::green);
50  log.style(clutchlog::level::info,
51  clutchlog::fmt::fg::magenta);
52  log.style(clutchlog::level::debug,
53  clutchlog::fmt::fg::cyan);
54  log.style(clutchlog::level::xdebug,
55  clutchlog::fmt::fg::blue);
56  std::ostringstream format;
57  clutchlog::fmt reset(clutchlog::fmt::typo::reset);
58  clutchlog::fmt discreet(clutchlog::fmt::fg::black);
59  clutchlog::fmt bold(clutchlog::fmt::typo::bold);
60  format << "{level_fmt}"
61  << "{level_letter}:"
62  << "{depth_marks} "
63  << bold("{msg}")
64  << discreet(" {hfill} ")
65  << "{level_fmt}{func}"
66  << discreet(" @ ")
67  << "{level_fmt}{file}"
68  << reset << ":"
69  << "{level_fmt}{line}"
70  << "\n";
71  log.format(format.str());
72 
73  // log.hfill_max(100);
74  log.out(std::clog);
75  log.depth_mark(">");
76  log.threshold(clutchlog::level::warning);
77 
78  if(argc <= 2) {
79  CLUTCHLOG(warning, "Log level not indicated, will default to xdebug");
80  log.threshold(clutchlog::level::xdebug);
81  } else {
82  try {
83  log.threshold(log.level_of(argv[1]));
84  } catch(std::out_of_range& err) {
85  CLUTCHLOG(critical,err.what());
86  exit(100);
87  }
88  }
89 
90  CLUTCHLOG(progress,"Start something");
91  f();
92  CLUTCHLOG(progress,"I have stopped");
93 }
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:314
CLUTCHLOG
#define CLUTCHLOG(LEVEL, WHAT)
Log a message at the given level.
Definition: clutchlog.h:81