BubbleProfiler  0.3.0
by Peter Athron, Csaba Balazs, Michael Bardsley, Andrew Fowlie, Dylan Harries & Graham White
logging_manager.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of BubbleProfiler.
3  *
4  * BubbleProfiler is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * BubbleProfiler is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with BubbleProfiler. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "logging_manager.hpp"
19 #include "error.hpp"
20 
21 #include <iostream>
22 
23 namespace BubbleProfiler {
24 
25 namespace logging {
26 
28 {
29  static Logging_manager instance;
30 
31  return instance;
32 }
33 
35 {
36  bool result = true;
37  switch (min_level) {
38  case Log_level::Trace: {
39  break;
40  }
41  case Log_level::Debug: {
42  if (level == Log_level::Trace) {
43  result = false;
44  }
45  break;
46  }
47  case Log_level::Info: {
48  if (level == Log_level::Trace ||
49  level == Log_level::Debug) {
50  result = false;
51  }
52  break;
53  }
54  case Log_level::Warning: {
55  if (level == Log_level::Trace ||
56  level == Log_level::Debug ||
57  level == Log_level::Info) {
58  result = false;
59  }
60  break;
61  }
62  case Log_level::Error: {
63  if (level != Log_level::Error &&
64  level != Log_level::Fatal) {
65  result = false;
66  }
67  break;
68  }
69  case Log_level::Fatal: {
70  if (level != Log_level::Fatal) {
71  result = false;
72  }
73  break;
74  }
75  default: {
76  throw Error("unrecognized log level");
77  }
78  }
79 
80  return result;
81 }
82 
83 void Logging_manager::log(const Log_message& message)
84 {
85  if (logging_enabled && above_min_level(message.get_log_level())) {
86  std::cerr << message.get_log_entry();
87  }
88 }
89 
90 } // namespace logging
91 
92 } // namespace BubbleProfiler
virtual Log_level get_log_level() const =0
static Logging_manager & get_manager()
void log(const Log_message &message)
virtual std::string get_log_entry() const =0