clutchlog  0.15
t-color16M.cpp
1 #include <iostream>
2 #include <limits>
3 
4 #include "../clutchlog/clutchlog.h"
5 
6 int main(/*const int argc, char* argv[]*/)
7 {
8  using typo = clutchlog::fmt::typo;
9  // using fg = clutchlog::fmt::fg;
10  // using bg = clutchlog::fmt::bg;
11 
12  clutchlog::fmt none;
13  clutchlog::fmt end(typo::reset);
14  clutchlog::fmt note(typo::bold);
15  clutchlog::fmt info(120,255,120); // greenish
16  clutchlog::fmt warning("#ff0055", typo::bold); // magentaish
17  clutchlog::fmt error(255,100,150, typo::bold); // redish magenta
18  clutchlog::fmt critical("#ffff00", "#ff0000"); // Yellow over red.
19 
20  auto& log = clutchlog::logger();
21  log.threshold(clutchlog::level::info);
22 
23  // Change a style.
24  log.style(clutchlog::level::critical, error);
25  CLUTCHLOG(critical,"Styles demo");
26 
27  CLUTCHLOG(info,"Either using functions...");
28  std::cout << none("No style: ") << std::endl;
29  std::cout << note("NOTE: bold") << std::endl;
30  std::cout << info("INFO: green") << std::endl;
31 
32  CLUTCHLOG(info,"... or tags.");
33  std::cout << warning << "WARNING" << end << ": bold magenta" << std::endl;
34  std::cout << error << "ERROR" << end << ": bold red" << std::endl;
35  std::cout << critical << "CRITICAL" << end << ": underlined black over red background" << std::endl;
36 
37  std::ostringstream format;
38  clutchlog::fmt discreet("#888888", typo::inverse);
39  format << "{level}: "
40  << discreet("{file}") << ":"
41  << clutchlog::fmt(/*front RGB*/200,150,0, /*back RGB*/0,0,0) << "{line}" // gold yellow over black
42  << clutchlog::fmt(typo::reset) << " {msg} ! " << std::endl;
43  log.format(format.str());
44  CLUTCHLOG(critical,"After having inserted styles within a new format template");
45 }
46 
47 
clutchlog::logger
static clutchlog & logger()
Get the logger instance.
Definition: clutchlog.h:306
clutchlog::fmt
Color and style formatter for ANSI terminal escape sequences.
Definition: clutchlog.h:376
CLUTCHLOG
#define CLUTCHLOG(LEVEL, WHAT)
Log a message at the given level.
Definition: clutchlog.h:98
clutchlog::fmt::typo
typo
Typographic style codes.
Definition: clutchlog.h:389