clutchlog 0.17
t-color.cpp
1#include <iostream>
2#include <limits>
3
4#include "../clutchlog/clutchlog.h"
5
6int 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(fg::green);
16 clutchlog::fmt warning(fg::magenta, typo::bold);
17 clutchlog::fmt error(fg::red, typo::bold);
18 clutchlog::fmt critical(bg::red, typo::underline, fg::black);
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(clutchlog::fmt::fg::white);
39 format << "{level}: "
40 << discreet("{file}:")
41 << clutchlog::fmt(clutchlog::fmt::fg::yellow) << "{line}"
42 << clutchlog::fmt(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}
Color and style formatter for ANSI terminal escape sequences.
Definition: clutchlog.h:380
typo
Typographic style codes.
Definition: clutchlog.h:393
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