Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
logger.hpp
Go to the documentation of this file.
1 #ifndef _LOGGER_HPP
2 #define _LOGGER_HPP
3 
4 #include <iostream>
5 #include <exception>
6 
7 #define _LOGGER_INFO
8 #define _LOGGER_COUT
9 #define _LOGGER_DEBUG
10 #define _LOGGER_WARNING
11 #define _LOGGER_ERROR
12 #define _LOGGER_ERROR_THROW_EXCEPTION
13 
14 namespace galaxis {
15  namespace utils {
16 
17  template <typename... Args>
18  void log_nonewline(const Args&... args) {
19 #ifdef _LOGGER_INFO
20  (std::clog << ... << args);
21 #endif
22  }
23 
24  template <typename... Args>
25  void log_cout(const Args&... args) {
26 #ifdef _LOGGER_COUT
27  (std::cout << ... << args);
28  std::cout << "\n";
29 #endif
30  }
31 
32  template <typename... Args>
33  void log(const Args&... args) {
34 #ifdef _LOGGER_INFO
35  (std::clog << ... << args);
36  std::clog << "\n";
37 #endif
38  }
39 
40  template <typename... Args>
41  void log_warning(const Args&... args) {
42 #ifdef _LOGGER_WARNING
43  std::clog << "WARNING: ";
44  (std::clog << ... << args);
45  std::clog << "\n";
46 #endif
47  }
48 
49  template <typename... Args>
50  void log_error(const Args&... args) {
51 #ifdef _LOGGER_ERROR
52  std::cerr << "ERROR: ";
53  (std::cerr << ... << args);
54  std::cerr << "\n";
55 #ifdef _LOGGER_ERROR_THROW_EXCEPTION
56  throw std::runtime_error("Look at the ERROR above. (thrown from utilities/.../logger.hpp)");
57 #endif
58 #endif
59  }
60 
61  template <typename... Args>
62  void log_debug(const Args&... args) {
63 #ifdef _LOGGER_DEBUG
64  std::cerr << "DEBUG: ";
65  (std::cerr << ... << args);
66  std::cerr << "\n";
67 #endif
68  }
69 
70  } // namespace utils
71 } // namespace galaxis
72 
73 #endif // _LOGGER_HPP
galaxis::utils::log_error
void log_error(const Args &... args)
Definition: logger.hpp:50
galaxis::utils::log_warning
void log_warning(const Args &... args)
Definition: logger.hpp:41
galaxis::utils::log_nonewline
void log_nonewline(const Args &... args)
Definition: logger.hpp:18
galaxis::utils::log_cout
void log_cout(const Args &... args)
Definition: logger.hpp:25
galaxis
Definition: MapClasses.hpp:10
galaxis::utils::log
void log(const Args &... args)
Definition: logger.hpp:33
galaxis::utils::log_debug
void log_debug(const Args &... args)
Definition: logger.hpp:62