flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
logger.cpp
Go to the documentation of this file.
1// ====================================================================
2// This file is part of FlexibleSUSY.
3//
4// FlexibleSUSY is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published
6// by the Free Software Foundation, either version 3 of the License,
7// or (at your option) any later version.
8//
9// FlexibleSUSY is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with FlexibleSUSY. If not, see
16// <http://www.gnu.org/licenses/>.
17// ====================================================================
18
19#include "logger.hpp"
20#include "config.h"
21#include "error.hpp"
22
23namespace flexiblesusy {
24
25namespace {
26
28 Print_colored(char const * const code) {
29 std::cerr << code;
30 }
32 std::cerr << "\033[0m";
33 }
34};
35
37 Print_green() : Print_colored("\033[0;32m") {}
38};
39
41 Print_blue() : Print_colored("\033[0;34m") {}
42};
43
45 Print_red() : Print_colored("\033[0;31m") {}
46};
47
49 Print_red_bold() : Print_colored("\033[1;31m") {}
50};
51
53 Print_red_background() : Print_colored("\033[41;1;37m") {}
54};
55
58 std::cerr << std::endl;
59 }
60};
61
62} // anonymous namespace
63
64#ifdef ENABLE_SILENT
65
66void print_verbose(std::function<void()>&&, const char*, int) {}
67void print_debug(std::function<void()>&&, const char*, int) {}
68void print_info(std::function<void()>&&, const char*, int) {}
69void print_warning(std::function<void()>&&, const char*, int) {}
70void print_error(std::function<void()>&&, const char*, int) {}
71void print_fatal(std::function<void()>&&, const char*, int) {}
72
73#else
74
75#ifdef ENABLE_VERBOSE
76void print_verbose(std::function<void()>&& f, const char* /* filename */, int /* line */ )
77{
78 const auto en = Append_endl();
79#ifdef ENABLE_COLORS
80 const auto cp = Print_green();
81#endif
82 f();
83}
84#else
85void print_verbose(std::function<void()>&&, const char*, int) {}
86#endif
87
88#ifdef ENABLE_DEBUG
89void print_debug(std::function<void()>&& f, const char* /* filename */, int /* line */)
90{
91 const auto en = Append_endl();
92#ifdef ENABLE_COLORS
93 const auto cp = Print_blue();
94#endif
95 f();
96}
97#else
98void print_debug(std::function<void()>&&, const char*, int) {}
99#endif
100
101void print_info(std::function<void()>&& f, const char* /* filename */, int /* line */)
102{
103 const auto en = Append_endl();
104 f();
105}
106
107void print_warning(std::function<void()>&& f, const char* /* filename */, int /* line */)
108{
109 const auto en = Append_endl();
110#ifdef ENABLE_COLORS
111 const auto cp = Print_red();
112#endif
113 f();
114}
115
116void print_error(std::function<void()>&& f, const char* /* filename */, int /* line */)
117{
118 const auto en = Append_endl();
119#ifdef ENABLE_COLORS
120 const auto cp = Print_red_bold();
121#endif
122 f();
123}
124
125void print_fatal(std::function<void()>&& f, const char* filename, int line)
126{
127 const auto en = Append_endl();
128#ifdef ENABLE_COLORS
129 const auto cp = Print_red_background();
130#endif
131
132 std::cerr << "Fatal: (file: " << filename << ", line: " << line << ") ";
133 f();
134 throw FatalError();
135}
136
137#endif
138
139} // namespace flexiblesusy
std::string filename(const std::string &file_name)
returns file name w/o directory
Definition: depgen.cpp:56
void print_error(std::function< void()> &&f, const char *, int)
Definition: logger.cpp:116
std::complex< double > f(double tau) noexcept
void print_debug(std::function< void()> &&, const char *, int)
Definition: logger.cpp:98
void print_fatal(std::function< void()> &&f, const char *filename, int line)
Definition: logger.cpp:125
void print_warning(std::function< void()> &&f, const char *, int)
Definition: logger.cpp:107
void print_info(std::function< void()> &&f, const char *, int)
Definition: logger.cpp:101
void print_verbose(std::function< void()> &&, const char *, int)
Definition: logger.cpp:85