Bayeux  3.4.1
Core Foundation library for SuperNEMO
logger_macros.h
Go to the documentation of this file.
1 //
4 // Copyright (c) 2013-2016 by Ben Morgan <bmorgan.warwick@gmail.com>
5 // Copyright (c) 2013-2016 by The University of Warwick
6 // Copyright (c) 2016-2018 by François Mauger <mauger@lpccaen.inp3.fr>
7 // Copyright (c) 2016-2018 by Université de Caen Normandie
8 //
9 // This file is part of datatools.
10 //
11 // datatools is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // datatools is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with datatools. If not, see <http://www.gnu.org/licenses/>.
23 
24 #ifndef DATATOOLS_DETAIL_LOGGER_MACROS_H
25 #define DATATOOLS_DETAIL_LOGGER_MACROS_H
26 
27 // Standard Library:
28 #include <sstream>
29 #include <iostream>
30 
31 // Third Party:
32 // - Boost:
33 #include <boost/current_function.hpp>
34 
35 // This project:
36 #include <datatools/logger.h>
37 
46 #define DT_LOG_FATAL(Priority, Message) \
47  { \
48  ::datatools::logger::priority _dt_xxx_p = Priority; \
49  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_FATAL) { \
50  std::ostringstream _dt_xxx_out; \
51  _dt_xxx_out << "[fatal:" << BOOST_CURRENT_FUNCTION << ":" << __LINE__ << "] " << Message << std::endl; \
52  std::cerr << _dt_xxx_out.str(); \
53  } \
54  }
55 
64 #define DT_LOG_CRITICAL(Priority, Message) \
65  { \
66  ::datatools::logger::priority _dt_xxx_p = Priority; \
67  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_CRITICAL) { \
68  std::ostringstream _dt_xxx_out; \
69  _dt_xxx_out << "[critical:" << BOOST_CURRENT_FUNCTION << ":" << __LINE__ << "] " << Message << std::endl; \
70  std::cerr << _dt_xxx_out.str(); \
71  } \
72  }
73 
82 #define DT_LOG_ERROR(Priority, Message) \
83  { \
84  ::datatools::logger::priority _dt_xxx_p = Priority; \
85  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_ERROR) { \
86  std::ostringstream _dt_xxx_out; \
87  _dt_xxx_out << "[error:" << BOOST_CURRENT_FUNCTION << ":" << __LINE__ << "] " << Message << std::endl; \
88  std::cerr << _dt_xxx_out.str(); \
89  } \
90  }
91 
100 #define DT_LOG_WARNING(Priority, Message) \
101  { \
102  ::datatools::logger::priority _dt_xxx_p = Priority; \
103  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_WARNING) { \
104  std::ostringstream _dt_xxx_out; \
105  _dt_xxx_out << "[warning:" << BOOST_CURRENT_FUNCTION << ":" << __LINE__ << "] " << Message << std::endl; \
106  std::cerr << _dt_xxx_out.str(); \
107  } \
108  }
109 
118 #define DT_LOG_NOTICE(Priority, Message) \
119  { \
120  ::datatools::logger::priority _dt_xxx_p = Priority; \
121  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_NOTICE) { \
122  std::ostringstream _dt_xxx_out; \
123  _dt_xxx_out << "[notice:" << BOOST_CURRENT_FUNCTION << ":" << __LINE__ << "] " << Message << std::endl; \
124  std::clog << _dt_xxx_out.str(); \
125  } \
126  }
127 
136 #define DT_LOG_INFORMATION(Priority, Message) \
137  { \
138  ::datatools::logger::priority _dt_xxx_p = Priority; \
139  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_INFORMATION) { \
140  std::ostringstream _dt_xxx_out; \
141  _dt_xxx_out << "[information:" << BOOST_CURRENT_FUNCTION << ":" << __LINE__ << "] " << Message << std::endl; \
142  std::clog << _dt_xxx_out.str(); \
143  } \
144  }
145 
147 #define DT_LOG_DEBUG(Priority, Message) \
148  { \
149  ::datatools::logger::priority _dt_xxx_p = Priority; \
150  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_DEBUG) { \
151  std::ostringstream _dt_xxx_out; \
152  _dt_xxx_out << "[debug:" << BOOST_CURRENT_FUNCTION << ":" << __LINE__ << "] " << Message << std::endl; \
153  std::cerr << _dt_xxx_out.str(); \
154  } \
155  }
156 
170 #define DT_LOG_INFORMATION_SHORT(Priority, Message) \
171  { \
172  ::datatools::logger::priority _dt_xxx_p = Priority; \
173  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_INFORMATION) { \
174  std::ostringstream _dt_xxx_out; \
175  _dt_xxx_out << "[debug] " << Message << std::endl; \
176  std::clog << _dt_xxx_out.str(); \
177  } \
178  }
179 
193 #define DT_LOG_NOTICE_SHORT(Priority, Message) \
194  { \
195  ::datatools::logger::priority _dt_xxx_p = Priority; \
196  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_NOTICE) { \
197  std::ostringstream _dt_xxx_out; \
198  _dt_xxx_out << "[debug] " << Message << std::endl; \
199  std::clog << _dt_xxx_out.str(); \
200  } \
201  }
202 
216 #define DT_LOG_DEBUG_SHORT(Priority, Message) \
217  { \
218  ::datatools::logger::priority _dt_xxx_p = Priority; \
219  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_DEBUG) { \
220  std::ostringstream _dt_xxx_out; \
221  _dt_xxx_out << "[debug] " << Message << std::endl; \
222  std::cerr << _dt_xxx_out.str(); \
223  } \
224  }
225 
227 #define DT_LOG_TRACE(Priority, Message) \
228  { \
229  ::datatools::logger::priority _dt_xxx_p = Priority; \
230  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_TRACE) { \
231  std::ostringstream _dt_xxx_out; \
232  _dt_xxx_out << "[trace:" << BOOST_CURRENT_FUNCTION << ":" << __LINE__ << "] " << Message << std::endl; \
233  std::cerr << _dt_xxx_out.str(); \
234  } \
235  }
236 
250 #define DT_LOG_TRACE_SHORT(Priority, Message) \
251  { \
252  ::datatools::logger::priority _dt_xxx_p = Priority; \
253  if (_dt_xxx_p == ::datatools::logger::PRIO_ALWAYS || _dt_xxx_p >= ::datatools::logger::PRIO_TRACE) { \
254  std::ostringstream _dt_xxx_out; \
255  _dt_xxx_out << "[trace] " << Message << std::endl; \
256  std::clog << _dt_xxx_out.str(); \
257  } \
258  }
259 
261 #define DT_LOG_TRACE_ENTERING(Priority) \
262  { \
263  DT_LOG_TRACE(Priority, "Entering..."); \
264  }
265 
267 #define DT_LOG_TRACE_EXITING(Priority) \
268  { \
269  DT_LOG_TRACE(Priority, "Exiting."); \
270  }
271 
272 #endif // DATATOOLS_DETAIL_LOGGER_MACROS_H
273 
274 // Local Variables: --
275 // mode: c++ --
276 // c-file-style: "gnu" --
277 // tab-width: 2 --
278 // End: --
Utilities for logging information.