virthttp  0.0
libvirt http interface
logger.hpp
Go to the documentation of this file.
1 //
2 // Created by hugo1 on 02.02.2019.
3 //
4 #pragma once
5 
6 #include <iostream>
7 #include <gsl/gsl>
8 
9 class Logger {
10  public:
11  template <typename... Ts> void raw(std::ostream& os, Ts... msg) {
12  (std::cout << ... << msg);
13  std::cout << std::endl;
14  }
15 
16  template <typename... Ts> void warning(Ts... msg) {
17  if (!isQuiet) {
18  if (isColored)
19  raw(std::cout, "\033[0;33mWARN: ", msg..., "\033[0m");
20  else
21  raw(std::cout, "WARN: ", msg...);
22  }
23  }
24 
25  template <typename... Ts> void error(Ts... msg) {
26  if (!isQuiet) {
27  if (isColored)
28  raw(std::cerr, "\033[0;31mERROR: ", msg..., "\033[0m");
29  else
30  raw(std::cerr, "ERROR: ", msg...);
31  }
32  }
33 
34  template <typename... Ts> void info(Ts... msg) {
35  if (!isQuiet)
36  raw(std::cout, "INFO: ", msg...);
37  }
38 
39  template <typename... Ts> void debug(Ts... msg) {
40  if (isDebug && !isQuiet) {
41  if (isColored)
42  raw(std::cout, "\033[0;32mDEBUG: ", msg..., "\033[0m");
43  else
44  raw(std::cout, "DEBUG: ", msg...);
45  }
46  }
47 
48  void setQuiet(bool b) { isQuiet = b; }
49  void setDebug(bool b) { isDebug = b; }
50  void setColored(bool b) { isColored = b; }
51 
52  private:
53  bool isQuiet = false;
54  bool isDebug = false;
55  bool isColored = false;
56 };
57 
58 inline Logger logger{}; // default ctor and dtor doesn't generate any code out of main
void raw(std::ostream &os, Ts...msg)
Definition: logger.hpp:11
void setColored(bool b)
Definition: logger.hpp:50
Definition: logger.hpp:9
void setDebug(bool b)
Definition: logger.hpp:49
void setQuiet(bool b)
Definition: logger.hpp:48
Logger logger
Definition: logger.hpp:58
void error(Ts...msg)
Definition: logger.hpp:25
void info(Ts...msg)
Definition: logger.hpp:34
void warning(Ts...msg)
Definition: logger.hpp:16
void debug(Ts...msg)
Definition: logger.hpp:39