rcutils  master
C API providing common utilities and data structures.
logging.h
Go to the documentation of this file.
1 // Copyright 2017 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCUTILS__LOGGING_H_
16 #define RCUTILS__LOGGING_H_
17 
18 #include <stdarg.h>
19 #include <stdbool.h>
20 #include <stdio.h>
21 
23 
24 #if __cplusplus
25 extern "C"
26 {
27 #endif
28 
32 
34 
47 
49 typedef struct rcutils_log_location_t
50 {
52  const char * function_name;
54  const char * file_name;
56  size_t line_number;
58 
61 {
67 };
68 
70 
78  rcutils_log_location_t *, // location
79  int, // severity
80  const char *, // name
81  const char *, // format
82  va_list * // args
83 );
84 
88 
90 
103 
105 
118 
120 
128 
130 
143 
145 
157 void rcutils_logging_set_severity_threshold(int severity);
158 
160 
179 void rcutils_log(
180  rcutils_log_location_t * location,
181  int severity,
182  const char * name,
183  const char * format,
184  ...);
185 
187 
211  rcutils_log_location_t * location,
212  int severity, const char * name, const char * format, va_list * args);
213 
214 // Provide the compiler with branch prediction information
215 #ifndef _WIN32
216 
220 # define RCUTILS_LIKELY(x) __builtin_expect((x), 1)
221 
225 # define RCUTILS_UNLIKELY(x) __builtin_expect((x), 0)
226 #else
227 
231 # define RCUTILS_LIKELY(x) (x)
232 
236 # define RCUTILS_UNLIKELY(x) (x)
237 #endif // _WIN32
238 
245 #define RCUTILS_LOGGING_AUTOINIT \
246  if (RCUTILS_UNLIKELY(!g_rcutils_logging_initialized)) { \
247  rcutils_logging_initialize(); \
248  }
249 
250 #if __cplusplus
251 }
252 #endif
253 
254 #endif // RCUTILS__LOGGING_H_
The info log level.
Definition: logging.h:63
The warn log level.
Definition: logging.h:64
void rcutils_logging_console_output_handler(rcutils_log_location_t *location, int severity, const char *name, const char *format, va_list *args)
The default output handler outputs log messages to the standard streams.
int g_rcutils_logging_severity_threshold
The global severity threshold before calling the output handler.
bool g_rcutils_logging_initialized
The flag if the logging system has been initialized.
void rcutils_log(rcutils_log_location_t *location, int severity, const char *name, const char *format,...)
Log a message.
void rcutils_logging_set_output_handler(rcutils_logging_output_handler_t function)
Set the current output handler.
size_t line_number
The line number containing the log call.
Definition: logging.h:56
void rcutils_logging_set_severity_threshold(int severity)
Set the global severity threshold.
void rcutils_logging_initialize()
Initialize the logging system.
void(* rcutils_logging_output_handler_t)(rcutils_log_location_t *, int, const char *, const char *, va_list *)
The function signature to log messages.
Definition: logging.h:77
rcutils_logging_output_handler_t rcutils_logging_get_output_handler()
Get the current output handler.
RCUTILS_LOG_SEVERITY
The severity levels of log message.
Definition: logging.h:60
const char * file_name
The name of the source file containing the log call.
Definition: logging.h:54
The structure identifying the caller location in the source code.
Definition: logging.h:49
#define RCUTILS_PUBLIC
Definition: visibility_control.h:48
The fatal log level.
Definition: logging.h:66
struct rcutils_log_location_t rcutils_log_location_t
The structure identifying the caller location in the source code.
rcutils_logging_output_handler_t g_rcutils_logging_output_handler
The function pointer of the current output handler.
int rcutils_logging_get_severity_threshold()
Get the global severity threshold.
The debug log level.
Definition: logging.h:62
const char * function_name
The name of the function containing the log call.
Definition: logging.h:52
The error log level.
Definition: logging.h:65