formatter.h
1 /*
2  * MoMEMta: a modular implementation of the Matrix Element Method
3  * Copyright (C) 2016 Universite catholique de Louvain (UCL), Belgium
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 // Heavily inspired by spdlog, Copyright(c) 2015 Gabi Melman
20 
21 #pragma once
22 
23 #include <momemta/impl/logger/log_msg.h>
24 
25 #include <chrono>
26 #include <iomanip>
27 #include <memory>
28 #include <string>
29 #include <thread>
30 #include <vector>
31 
32 namespace logger {
33 
34 class formatter {
35 public:
36  virtual ~formatter() {}
37  virtual void format(details::log_msg& msg) = 0;
38 };
39 
40 class full_formatter: public formatter {
41 public:
42  void format(details::log_msg& msg) override;
43 
44 protected:
45  virtual void format_level(details::log_msg& msg);
46 };
47 
49 public:
51  const std::string reset = "\033[00m";
52  const std::string bold = "\033[1m";
53  const std::string dark = "\033[2m";
54  const std::string underline = "\033[4m";
55  const std::string blink = "\033[5m";
56  const std::string reverse = "\033[7m";
57  const std::string concealed = "\033[8m";
58 
59  // Foreground colors
60  const std::string grey = "\033[90m";
61  const std::string red = "\033[31m";
62  const std::string green = "\033[32m";
63  const std::string yellow = "\033[33m";
64  const std::string blue = "\033[34m";
65  const std::string magenta = "\033[35m";
66  const std::string cyan = "\033[36m";
67  const std::string white = "\033[37m";
68 
70  const std::string on_grey = "\033[40m";
71  const std::string on_red = "\033[41m";
72  const std::string on_green = "\033[42m";
73  const std::string on_yellow = "\033[43m";
74  const std::string on_blue = "\033[44m";
75  const std::string on_magenta = "\033[45m";
76  const std::string on_cyan = "\033[46m";
77  const std::string on_white = "\033[47m";
78 
79 protected:
80  void format_level(details::log_msg& msg) override;
81 };
82 
83 }