rcutils  master
C API providing common utilities and data structures.
Classes | Typedefs | Enumerations | Functions | Variables
logging.h File Reference
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include "rcutils/visibility_control.h"
Include dependency graph for logging.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rcl_log_location_t
 The structure identifying the caller location in the source code. More...
 

Typedefs

typedef struct rcl_log_location_t rcl_log_location_t
 The structure identifying the caller location in the source code. More...
 
typedef void(* rcl_logging_output_handler_t) (rcl_log_location_t *, int, const char *, const char *, va_list *)
 The function signature to log messages. More...
 

Enumerations

enum  RCUTILS_LOG_SEVERITY {
  RCUTILS_LOG_SEVERITY_DEBUG = 0, RCUTILS_LOG_SEVERITY_INFO = 1, RCUTILS_LOG_SEVERITY_WARN = 2, RCUTILS_LOG_SEVERITY_ERROR = 3,
  RCUTILS_LOG_SEVERITY_FATAL = 4
}
 The severity levels of log message. More...
 

Functions

void rcl_logging_initialize ()
 Initialize the logging system. More...
 
rcl_logging_output_handler_t rcl_logging_get_output_handler ()
 Get the current output handler. More...
 
void rcl_logging_set_output_handler (rcl_logging_output_handler_t function)
 Set the current output handler. More...
 
int rcl_logging_get_severity_threshold ()
 Get the global severity threshold. More...
 
void rcl_logging_set_severity_threshold (int severity)
 Set the global severity threshold. More...
 
void rcl_log (rcl_log_location_t *location, int severity, const char *name, const char *format,...)
 Log a message. More...
 
void rcl_logging_console_output_handler (rcl_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. More...
 

Variables

bool g_rcl_logging_initialized
 The flag if the logging system has been initialized. More...
 
rcl_logging_output_handler_t g_rcl_logging_output_handler
 The function pointer of the current output handler. More...
 
int g_rcl_logging_severity_threshold
 The global severity threshold before calling the output handler. More...
 

Typedef Documentation

The structure identifying the caller location in the source code.

typedef void(* rcl_logging_output_handler_t) (rcl_log_location_t *,int,const char *,const char *,va_list *)

The function signature to log messages.

Parameters
Thepointer to the location struct
Theseverity level
Thename of the logger
Theformat string
Thevariable argument list

Enumeration Type Documentation

The severity levels of log message.

Enumerator
RCUTILS_LOG_SEVERITY_DEBUG 

The debug log level.

RCUTILS_LOG_SEVERITY_INFO 

The info log level.

RCUTILS_LOG_SEVERITY_WARN 

The warn log level.

RCUTILS_LOG_SEVERITY_ERROR 

The error log level.

RCUTILS_LOG_SEVERITY_FATAL 

The fatal log level.

Function Documentation

void rcl_logging_initialize ( )

Initialize the logging system.

The function is called automatically when using the logging macros.


Attribute Adherence
Allocates Memory No
Thread-Safe No
Uses Atomics No
Lock-Free Yes
rcl_logging_output_handler_t rcl_logging_get_output_handler ( )

Get the current output handler.


Attribute Adherence
Allocates Memory No
Thread-Safe No
Uses Atomics No
Lock-Free Yes
Returns
The function pointer of the current output handler.
void rcl_logging_set_output_handler ( rcl_logging_output_handler_t  function)

Set the current output handler.


Attribute Adherence
Allocates Memory No
Thread-Safe No
Uses Atomics No
Lock-Free Yes
Parameters
functionThe function pointer of the output handler to be used.
int rcl_logging_get_severity_threshold ( )

Get the global severity threshold.


Attribute Adherence
Allocates Memory No
Thread-Safe No
Uses Atomics No
Lock-Free Yes
Returns
The severity threshold.
void rcl_logging_set_severity_threshold ( int  severity)

Set the global severity threshold.


Attribute Adherence
Allocates Memory No
Thread-Safe No
Uses Atomics No
Lock-Free Yes
Parameters
severityThe severity threshold to be used.
void rcl_log ( rcl_log_location_t location,
int  severity,
const char *  name,
const char *  format,
  ... 
)

Log a message.

The attributes of this function are also being influenced by the currently set output handler.


Attribute Adherence
Allocates Memory No
Thread-Safe No
Uses Atomics No
Lock-Free Yes
Parameters
locationThe pointer to the location struct
severityThe severity level
nameThe name of the logger
formatThe format string
...The variable arguments
void rcl_logging_console_output_handler ( rcl_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.

The messages with a severity DEBUG and INFO are written to stdout. The messages with a severity WARN, ERROR, and FATAL are written to stderr. For each message the severity and name is prepended and the location information is appended when available.


Attribute Adherence
Allocates Memory No, for formatted messages <= 1023 characters

| Yes, for formatted messages >= 1024 characters Thread-Safe | Yes, if the underlying *printf functions are Uses Atomics | No Lock-Free | Yes

Parameters
locationThe pointer to the location struct
severityThe severity level
nameThe name of the logger
formatThe format string
argsThe variable argument list

Variable Documentation

bool g_rcl_logging_initialized

The flag if the logging system has been initialized.

rcl_logging_output_handler_t g_rcl_logging_output_handler

The function pointer of the current output handler.

int g_rcl_logging_severity_threshold

The global severity threshold before calling the output handler.

The global severity threshold is being checked after the conditions when using the various logging macros.

Parameters
severityThe global severity threshold to be used.