NASA Astrobee Robot Software  Astrobee Version:
Flight software for the Astrobee robots operating inside the International Space Station.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
logger.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef LOCALIZATION_COMMON_LOGGER_H_
20 #define LOCALIZATION_COMMON_LOGGER_H_
21 
22 // Needed for ros include
24 
25 #include <ros/console.h>
26 
27 #include <glog/logging.h>
28 
29 #include <sstream>
30 #include <string>
31 
32 // Select logger here
33 // TODO(rsoussan): Add compile definition for this?
34 #define USE_ROS_LOGGING
35 // #define USE_GLOG_LOGGING
36 
37 #ifdef USE_ROS_LOGGING
38 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
39 
40 // clang-format off
41 #define LogInfo(msg) \
42  do { \
43  std::stringstream ss; \
44  ss << __FILENAME__ << ":" << __LINE__ << ": " << msg << std::endl; \
45  ROS_INFO_STREAM(ss.str()); \
46  } while (0)
47 
48 #define LogWarning(msg) \
49  do { \
50  std::stringstream ss; \
51  ss << __FILENAME__ << ":" << __LINE__ << ": " << msg << std::endl; \
52  ROS_WARN_STREAM(ss.str()); \
53  } while (0)
54 
55 #define LogError(msg) \
56  do { \
57  std::stringstream ss; \
58  ss << __FILENAME__ << ":" << __LINE__ << ": " << msg << std::endl; \
59  ROS_ERROR_STREAM(ss.str()); \
60  } while (0)
61 
62 #define LogFatal(msg) \
63  do { \
64  std::stringstream ss; \
65  ss << __FILENAME__ << ":" << __LINE__ << ": " << msg << std::endl; \
66  ROS_FATAL_STREAM(ss.str()); \
67  } while (0)
68 
69 #define LogDebug(msg) \
70  do { \
71  std::stringstream ss; \
72  ss << __FILENAME__ << ":" << __LINE__ << ": " << msg << std::endl; \
73  ROS_DEBUG_STREAM(ss.str()); \
74  } while (0)
75 
76 #define LogInfoEveryN(n, msg) \
77  do { \
78  static int count = 0; \
79  ++count; \
80  if (count % n == 0) { \
81  std::stringstream ss; \
82  ss << __FILENAME__ << ":" << __LINE__ << ": " << msg << std::endl; \
83  ROS_INFO_STREAM(ss.str()); \
84  } \
85  } while (0)
86 
87 #define LogWarningEveryN(n, msg) \
88  do { \
89  static int count = 0; \
90  ++count; \
91  if (count % n == 0) { \
92  std::stringstream ss; \
93  ss << __FILENAME__ << ":" << __LINE__ << ": " << msg << std::endl; \
94  ROS_WARN_STREAM(ss.str()); \
95  } \
96  } while (0)
97 
98 #define LogErrorEveryN(n, msg) \
99  do { \
100  static int count = 0; \
101  ++count; \
102  if (count % n == 0) { \
103  std::stringstream ss; \
104  ss << __FILENAME__ << ":" << __LINE__ << ": " << msg << std::endl; \
105  ROS_ERROR_STREAM(ss.str()); \
106  } \
107  } while (0)
108 
109 #define LogDebugEveryN(n, msg) \
110  do { \
111  static int count = 0; \
112  ++count; \
113  if (count % n == 0) { \
114  std::stringstream ss; \
115  ss << __FILENAME__ << ":" << __LINE__ << ": " << msg << std::endl; \
116  ROS_DEBUG_STREAM(ss.str()); \
117  } \
118  } while (0)
119 
120 #elif defined(USE_GLOG_LOGGING)
121 #define LogInfo(msg) \
122  do { \
123  LOG(INFO) << msg; \
124  } while (0)
125 #define LogWarning(msg) \
126  do { \
127  LOG(WARNING) << msg; \
128  } while (0)
129 
130 #define LogError(msg) \
131  do { \
132  LOG(ERROR) << msg; \
133  } while (0)
134 
135 #define LogFatal(msg) \
136  do { \
137  LOG(FATAL) << msg; \
138  } while (0)
139 
140 #define LogDebug(msg) \
141  do { \
142  VLOG(2) << msg; \
143  } while (0)
144 
145 #define LogInfoEveryN(n, msg) \
146  do { \
147  LOG_EVERY_N(INFO, n) << msg; \
148  } while (0)
149 
150 #define LogWarningEveryN(n, msg) \
151  do { \
152  LOG_EVERY_N(WARNING, n) << msg; \
153  } while (0)
154 
155 #define LogErrorEveryN(n, msg) \
156  do { \
157  LOG_EVERY_N(ERROR, n) << msg; \
158  } while (0)
159 
160 #define LogDebugEveryN(n, msg) \
161  do { \
162  DLOG_EVERY_N(INFO, n) << msg; \
163  } while (0)
164 
165 #endif
166 // clang-format on
167 #endif // LOCALIZATION_COMMON_LOGGER_H_
eigen_vectors.h