common.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 <atomic>
24 #include <chrono>
25 #include <memory>
26 
27 namespace logger {
28 
29 class formatter;
30 class logger;
31 
32 namespace sinks {
33 class sink;
34 }
35 
36 using formatter_ptr = std::shared_ptr<::logger::formatter>;
37 using level_t = std::atomic<int>;
38 using logger_ptr = std::shared_ptr<::logger::logger>;
39 using log_clock = std::chrono::system_clock;
40 using sink_ptr = std::shared_ptr<sinks::sink>;
41 
42 }
43 
44 namespace logging {
45 
46 namespace level {
47 
48 typedef enum {
49  trace = 0,
50  debug = 1,
51  info = 2,
52  warning = 3,
53  error = 4,
54  fatal = 5,
55  off = 6
56 } level_enum;
57 
58 static const char* level_names[] { "trace", "debug", "info", "warning", "error", "fatal", "off" };
59 
60 inline const char* to_str(logging::level::level_enum l) {
61  return level_names[l];
62 }
63 
64 }
65 
66 }