rclcpp  master
C++ ROS Client Library API
logging.hpp
Go to the documentation of this file.
1 // generated from rclcpp/resource/logging.hpp.em
2 
3 // Copyright 2017 Open Source Robotics Foundation, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef RCLCPP__LOGGING_HPP_
18 #define RCLCPP__LOGGING_HPP_
19 
20 #include <type_traits>
21 
22 #include "rclcpp/logger.hpp"
23 #include "rcutils/logging_macros.h"
24 
25 // These are used for compiling out logging macros lower than a minimum severity.
26 #define RCLCPP_LOG_MIN_SEVERITY_DEBUG 0
27 #define RCLCPP_LOG_MIN_SEVERITY_INFO 1
28 #define RCLCPP_LOG_MIN_SEVERITY_WARN 2
29 #define RCLCPP_LOG_MIN_SEVERITY_ERROR 3
30 #define RCLCPP_LOG_MIN_SEVERITY_FATAL 4
31 #define RCLCPP_LOG_MIN_SEVERITY_NONE 5
32 
39 #ifndef RCLCPP_LOG_MIN_SEVERITY
40 #define RCLCPP_LOG_MIN_SEVERITY RCLCPP_LOG_MIN_SEVERITY_DEBUG
41 #endif
42 
45 #if (RCLCPP_LOG_MIN_SEVERITY > RCLCPP_LOG_MIN_SEVERITY_DEBUG)
47 // empty logging macros for severity DEBUG when being disabled at compile time
49 #define RCLCPP_DEBUG(...)
50 #define RCLCPP_DEBUG_ONCE(...)
52 #define RCLCPP_DEBUG_EXPRESSION(...)
54 #define RCLCPP_DEBUG_FUNCTION(...)
56 #define RCLCPP_DEBUG_SKIPFIRST(...)
58 
59 #else
60 
66 #define RCLCPP_DEBUG(logger, ...) \
67  static_assert( \
68  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
69  "First argument to logging macros must be an rclcpp::Logger"); \
70  RCUTILS_LOG_DEBUG_NAMED( \
71  logger.get_name(), \
72  __VA_ARGS__)
73 
81 #define RCLCPP_DEBUG_ONCE(logger, ...) \
82  static_assert( \
83  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
84  "First argument to logging macros must be an rclcpp::Logger"); \
85  RCUTILS_LOG_DEBUG_ONCE_NAMED( \
86  logger.get_name(), \
87  __VA_ARGS__)
88 
97 #define RCLCPP_DEBUG_EXPRESSION(logger, expression, ...) \
98  static_assert( \
99  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
100  "First argument to logging macros must be an rclcpp::Logger"); \
101  RCUTILS_LOG_DEBUG_EXPRESSION_NAMED( \
102  expression, \
103  logger.get_name(), \
104  __VA_ARGS__)
105 
114 #define RCLCPP_DEBUG_FUNCTION(logger, function, ...) \
115  static_assert( \
116  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
117  "First argument to logging macros must be an rclcpp::Logger"); \
118  RCUTILS_LOG_DEBUG_FUNCTION_NAMED( \
119  function, \
120  logger.get_name(), \
121  __VA_ARGS__)
122 
130 #define RCLCPP_DEBUG_SKIPFIRST(logger, ...) \
131  static_assert( \
132  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
133  "First argument to logging macros must be an rclcpp::Logger"); \
134  RCUTILS_LOG_DEBUG_SKIPFIRST_NAMED( \
135  logger.get_name(), \
136  __VA_ARGS__)
137 
138 #endif
139 
143 #if (RCLCPP_LOG_MIN_SEVERITY > RCLCPP_LOG_MIN_SEVERITY_INFO)
145 // empty logging macros for severity INFO when being disabled at compile time
147 #define RCLCPP_INFO(...)
148 #define RCLCPP_INFO_ONCE(...)
150 #define RCLCPP_INFO_EXPRESSION(...)
152 #define RCLCPP_INFO_FUNCTION(...)
154 #define RCLCPP_INFO_SKIPFIRST(...)
156 
157 #else
158 
164 #define RCLCPP_INFO(logger, ...) \
165  static_assert( \
166  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
167  "First argument to logging macros must be an rclcpp::Logger"); \
168  RCUTILS_LOG_INFO_NAMED( \
169  logger.get_name(), \
170  __VA_ARGS__)
171 
179 #define RCLCPP_INFO_ONCE(logger, ...) \
180  static_assert( \
181  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
182  "First argument to logging macros must be an rclcpp::Logger"); \
183  RCUTILS_LOG_INFO_ONCE_NAMED( \
184  logger.get_name(), \
185  __VA_ARGS__)
186 
195 #define RCLCPP_INFO_EXPRESSION(logger, expression, ...) \
196  static_assert( \
197  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
198  "First argument to logging macros must be an rclcpp::Logger"); \
199  RCUTILS_LOG_INFO_EXPRESSION_NAMED( \
200  expression, \
201  logger.get_name(), \
202  __VA_ARGS__)
203 
212 #define RCLCPP_INFO_FUNCTION(logger, function, ...) \
213  static_assert( \
214  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
215  "First argument to logging macros must be an rclcpp::Logger"); \
216  RCUTILS_LOG_INFO_FUNCTION_NAMED( \
217  function, \
218  logger.get_name(), \
219  __VA_ARGS__)
220 
228 #define RCLCPP_INFO_SKIPFIRST(logger, ...) \
229  static_assert( \
230  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
231  "First argument to logging macros must be an rclcpp::Logger"); \
232  RCUTILS_LOG_INFO_SKIPFIRST_NAMED( \
233  logger.get_name(), \
234  __VA_ARGS__)
235 
236 #endif
237 
241 #if (RCLCPP_LOG_MIN_SEVERITY > RCLCPP_LOG_MIN_SEVERITY_WARN)
243 // empty logging macros for severity WARN when being disabled at compile time
245 #define RCLCPP_WARN(...)
246 #define RCLCPP_WARN_ONCE(...)
248 #define RCLCPP_WARN_EXPRESSION(...)
250 #define RCLCPP_WARN_FUNCTION(...)
252 #define RCLCPP_WARN_SKIPFIRST(...)
254 
255 #else
256 
262 #define RCLCPP_WARN(logger, ...) \
263  static_assert( \
264  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
265  "First argument to logging macros must be an rclcpp::Logger"); \
266  RCUTILS_LOG_WARN_NAMED( \
267  logger.get_name(), \
268  __VA_ARGS__)
269 
277 #define RCLCPP_WARN_ONCE(logger, ...) \
278  static_assert( \
279  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
280  "First argument to logging macros must be an rclcpp::Logger"); \
281  RCUTILS_LOG_WARN_ONCE_NAMED( \
282  logger.get_name(), \
283  __VA_ARGS__)
284 
293 #define RCLCPP_WARN_EXPRESSION(logger, expression, ...) \
294  static_assert( \
295  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
296  "First argument to logging macros must be an rclcpp::Logger"); \
297  RCUTILS_LOG_WARN_EXPRESSION_NAMED( \
298  expression, \
299  logger.get_name(), \
300  __VA_ARGS__)
301 
310 #define RCLCPP_WARN_FUNCTION(logger, function, ...) \
311  static_assert( \
312  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
313  "First argument to logging macros must be an rclcpp::Logger"); \
314  RCUTILS_LOG_WARN_FUNCTION_NAMED( \
315  function, \
316  logger.get_name(), \
317  __VA_ARGS__)
318 
326 #define RCLCPP_WARN_SKIPFIRST(logger, ...) \
327  static_assert( \
328  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
329  "First argument to logging macros must be an rclcpp::Logger"); \
330  RCUTILS_LOG_WARN_SKIPFIRST_NAMED( \
331  logger.get_name(), \
332  __VA_ARGS__)
333 
334 #endif
335 
339 #if (RCLCPP_LOG_MIN_SEVERITY > RCLCPP_LOG_MIN_SEVERITY_ERROR)
341 // empty logging macros for severity ERROR when being disabled at compile time
343 #define RCLCPP_ERROR(...)
344 #define RCLCPP_ERROR_ONCE(...)
346 #define RCLCPP_ERROR_EXPRESSION(...)
348 #define RCLCPP_ERROR_FUNCTION(...)
350 #define RCLCPP_ERROR_SKIPFIRST(...)
352 
353 #else
354 
360 #define RCLCPP_ERROR(logger, ...) \
361  static_assert( \
362  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
363  "First argument to logging macros must be an rclcpp::Logger"); \
364  RCUTILS_LOG_ERROR_NAMED( \
365  logger.get_name(), \
366  __VA_ARGS__)
367 
375 #define RCLCPP_ERROR_ONCE(logger, ...) \
376  static_assert( \
377  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
378  "First argument to logging macros must be an rclcpp::Logger"); \
379  RCUTILS_LOG_ERROR_ONCE_NAMED( \
380  logger.get_name(), \
381  __VA_ARGS__)
382 
391 #define RCLCPP_ERROR_EXPRESSION(logger, expression, ...) \
392  static_assert( \
393  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
394  "First argument to logging macros must be an rclcpp::Logger"); \
395  RCUTILS_LOG_ERROR_EXPRESSION_NAMED( \
396  expression, \
397  logger.get_name(), \
398  __VA_ARGS__)
399 
408 #define RCLCPP_ERROR_FUNCTION(logger, function, ...) \
409  static_assert( \
410  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
411  "First argument to logging macros must be an rclcpp::Logger"); \
412  RCUTILS_LOG_ERROR_FUNCTION_NAMED( \
413  function, \
414  logger.get_name(), \
415  __VA_ARGS__)
416 
424 #define RCLCPP_ERROR_SKIPFIRST(logger, ...) \
425  static_assert( \
426  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
427  "First argument to logging macros must be an rclcpp::Logger"); \
428  RCUTILS_LOG_ERROR_SKIPFIRST_NAMED( \
429  logger.get_name(), \
430  __VA_ARGS__)
431 
432 #endif
433 
437 #if (RCLCPP_LOG_MIN_SEVERITY > RCLCPP_LOG_MIN_SEVERITY_FATAL)
439 // empty logging macros for severity FATAL when being disabled at compile time
441 #define RCLCPP_FATAL(...)
442 #define RCLCPP_FATAL_ONCE(...)
444 #define RCLCPP_FATAL_EXPRESSION(...)
446 #define RCLCPP_FATAL_FUNCTION(...)
448 #define RCLCPP_FATAL_SKIPFIRST(...)
450 
451 #else
452 
458 #define RCLCPP_FATAL(logger, ...) \
459  static_assert( \
460  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
461  "First argument to logging macros must be an rclcpp::Logger"); \
462  RCUTILS_LOG_FATAL_NAMED( \
463  logger.get_name(), \
464  __VA_ARGS__)
465 
473 #define RCLCPP_FATAL_ONCE(logger, ...) \
474  static_assert( \
475  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
476  "First argument to logging macros must be an rclcpp::Logger"); \
477  RCUTILS_LOG_FATAL_ONCE_NAMED( \
478  logger.get_name(), \
479  __VA_ARGS__)
480 
489 #define RCLCPP_FATAL_EXPRESSION(logger, expression, ...) \
490  static_assert( \
491  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
492  "First argument to logging macros must be an rclcpp::Logger"); \
493  RCUTILS_LOG_FATAL_EXPRESSION_NAMED( \
494  expression, \
495  logger.get_name(), \
496  __VA_ARGS__)
497 
506 #define RCLCPP_FATAL_FUNCTION(logger, function, ...) \
507  static_assert( \
508  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
509  "First argument to logging macros must be an rclcpp::Logger"); \
510  RCUTILS_LOG_FATAL_FUNCTION_NAMED( \
511  function, \
512  logger.get_name(), \
513  __VA_ARGS__)
514 
522 #define RCLCPP_FATAL_SKIPFIRST(logger, ...) \
523  static_assert( \
524  ::std::is_same<std::remove_reference<decltype(logger)>::type, ::rclcpp::Logger>::value, \
525  "First argument to logging macros must be an rclcpp::Logger"); \
526  RCUTILS_LOG_FATAL_SKIPFIRST_NAMED( \
527  logger.get_name(), \
528  __VA_ARGS__)
529 
530 #endif
531 
533 
534 #endif // RCLCPP__LOGGING_HPP_