Robowflex  v0.1
Making MoveIt Easy
log.h
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #ifndef ROBOWFLEX_LOGGING_
4 #define ROBOWFLEX_LOGGING_
5 
6 #include <boost/format.hpp>
7 #include <ros/console.h>
8 
9 /** \file Logging
10  * Functions for logging throughout Robowflex. Uses the boost::format format string syntax.
11  * See https://www.boost.org/doc/libs/1_66_0/libs/format/doc/format.html for details.
12  * All functions follow a 'printf' style, where there is a format string followed by arguments.
13  * e.g., RBX_ERROR("%s failed! Try %+08d", "test", 10)
14  * RBX_ERROR("%1%: %2%", "argument 1", "argument 2")
15  *
16  * There are the following debugging levels available, in descending order of priority:
17  * - FATAL, which also causes the program to terminate.
18  * - ERROR
19  * - WARN
20  * - INFO
21  * - DEBUG, which are not visible unless enabled (e.g., with showUpToDebug())
22  *
23  * Currently, all logging is done through rosconsole. It is good practice to use the defined
24  * macros here for abstraction purpose.
25  */
26 
27 namespace robowflex
28 {
29  /** \brief Logging functions.
30  */
31  namespace log
32  {
33  /** \brief Recursion base case, return string form of formatted arguments.
34  * \param[in] f Formatter.
35  * \return String of formatted arguments.
36  */
38 
39  /** \brief Recursion base case, return string form of formatted arguments.
40  * \tparam[in] T Type of first argument.
41  * \tparam[in] Args format argument types.
42  * \param[in] f Formatter.
43  * \param[in] t First argument.
44  * \param[in] args Remaining format arguments.
45  * \return String of formatted arguments.
46  */
47  template <class T, class... Args>
48  std::string formatRecurse(boost::format &f, T &&t, Args &&... args)
49  {
50  return formatRecurse(f % std::forward<T>(t), std::forward<Args>(args)...);
51  }
52 
53  /** \brief Recursion base case, return string form of formatted arguments.
54  * \tparam[in] Args format argument types.
55  * \param[in] fmt Format string.
56  * \param[in] args Format arguments.
57  * \return String of formatted arguments.
58  */
59  template <typename... Args>
60  std::string format(const std::string &fmt, Args &&... args)
61  {
62  boost::format f(fmt);
63  return formatRecurse(f, std::forward<Args>(args)...);
64  }
65 
66  /** \brief Show all logging messages fatal and above.
67  */
68  void showUpToFatal();
69 
70  /** \brief Show all logging messages error and above.
71  */
72  void showUpToError();
73 
74  /** \brief Show all logging messages warning and above.
75  */
76  void showUpToWarning();
77 
78  /** \brief Show all logging messages info and above.
79  */
80  void showUpToInfo();
81 
82  /** \brief Show all logging messages debug and above.
83  */
84  void showUpToDebug();
85  } // namespace log
86 } // namespace robowflex
87 
88 /**
89  * \def RBX_FATAL
90  * \brief Output a fatal logging message.
91  * \param[in] fmt Format string (see boost::format specification)
92  * \param[in] ... Format arguments.
93  */
94 #define RBX_FATAL(fmt, ...) ROS_FATAL_STREAM(robowflex::log::format(fmt, ##__VA_ARGS__).c_str())
95 
96 /**
97  * \def RBX_ERROR
98  * \brief Output a error logging message.
99  * \param[in] fmt Format string (see boost::format specification)
100  * \param[in] ... Format arguments.
101  */
102 #define RBX_ERROR(fmt, ...) ROS_ERROR_STREAM(robowflex::log::format(fmt, ##__VA_ARGS__).c_str())
103 
104 /**
105  * \def RBX_WARN
106  * \brief Output a warning logging message.
107  * \param[in] fmt Format string (see boost::format specification)
108  * \param[in] ... Format arguments.
109  */
110 #define RBX_WARN(fmt, ...) ROS_WARN_STREAM(robowflex::log::format(fmt, ##__VA_ARGS__).c_str())
111 
112 /**
113  * \def RBX_INFO
114  * \brief Output a info logging message.
115  * \param[in] fmt Format string (see boost::format specification)
116  * \param[in] ... Format arguments.
117  */
118 #define RBX_INFO(fmt, ...) ROS_INFO_STREAM(robowflex::log::format(fmt, ##__VA_ARGS__).c_str())
119 
120 /**
121  * \def RBX_DEBUG
122  * \brief Output a debug logging message.
123  * \param[in] fmt Format string (see boost::format specification)
124  * \param[in] ... Format arguments.
125  */
126 #define RBX_DEBUG(fmt, ...) ROS_DEBUG_STREAM(robowflex::log::format(fmt, ##__VA_ARGS__).c_str())
127 
128 #endif
std::string format(const std::string &fmt, Args &&... args)
Recursion base case, return string form of formatted arguments.
Definition: log.h:60
void showUpToDebug()
Show all logging messages debug and above.
Definition: log.cpp:41
void showUpToWarning()
Show all logging messages warning and above.
Definition: log.cpp:31
void showUpToInfo()
Show all logging messages info and above.
Definition: log.cpp:36
void showUpToError()
Show all logging messages error and above.
Definition: log.cpp:26
void showUpToFatal()
Show all logging messages fatal and above.
Definition: log.cpp:21
std::string formatRecurse(boost::format &f)
Recursion base case, return string form of formatted arguments.
Definition: log.cpp:16
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25