Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the temporary variable in RCUTILS_LOGGING_AUTOINIT #290

Merged
merged 3 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions include/rcutils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,17 +516,18 @@ void rcutils_logging_console_output_handler(
* All logging macros ensure that this has been called once.
*/
#define RCUTILS_LOGGING_AUTOINIT \
if (RCUTILS_UNLIKELY(!g_rcutils_logging_initialized)) { \
rcutils_ret_t ret = rcutils_logging_initialize(); \
if (ret != RCUTILS_RET_OK) { \
RCUTILS_SAFE_FWRITE_TO_STDERR( \
"[rcutils|" __FILE__ ":" RCUTILS_STRINGIFY(__LINE__) \
"] error initializing logging: "); \
RCUTILS_SAFE_FWRITE_TO_STDERR(rcutils_get_error_string().str); \
RCUTILS_SAFE_FWRITE_TO_STDERR("\n"); \
rcutils_reset_error(); \
do { \
if (RCUTILS_UNLIKELY(!g_rcutils_logging_initialized)) { \
if (rcutils_logging_initialize() != RCUTILS_RET_OK) { \
RCUTILS_SAFE_FWRITE_TO_STDERR( \
"[rcutils|" __FILE__ ":" RCUTILS_STRINGIFY(__LINE__) \
"] error initializing logging: "); \
RCUTILS_SAFE_FWRITE_TO_STDERR(rcutils_get_error_string().str); \
RCUTILS_SAFE_FWRITE_TO_STDERR("\n"); \
rcutils_reset_error(); \
} \
} \
}
} while (0)

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion resource/logging_macros.h.em
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extern "C"
*/
#define RCUTILS_LOG_COND_NAMED(severity, condition_before, condition_after, name, ...) \
do { \
RCUTILS_LOGGING_AUTOINIT \
RCUTILS_LOGGING_AUTOINIT; \
static rcutils_log_location_t __rcutils_logging_location = {__func__, __FILE__, __LINE__}; \
if (rcutils_logging_logger_is_enabled_for(name, severity)) { \
condition_before \
Expand Down
22 changes: 9 additions & 13 deletions src/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,39 +342,35 @@ rcutils_logging_severity_level_from_string(

rcutils_logging_output_handler_t rcutils_logging_get_output_handler(void)
{
RCUTILS_LOGGING_AUTOINIT
RCUTILS_LOGGING_AUTOINIT;
return g_rcutils_logging_output_handler;
}

void rcutils_logging_set_output_handler(rcutils_logging_output_handler_t function)
{
// *INDENT-OFF* (prevent uncrustify from making unnecessary indents here)
RCUTILS_LOGGING_AUTOINIT
RCUTILS_LOGGING_AUTOINIT;
g_rcutils_logging_output_handler = function;
// *INDENT-ON*
}

int rcutils_logging_get_default_logger_level(void)
{
RCUTILS_LOGGING_AUTOINIT
RCUTILS_LOGGING_AUTOINIT;
return g_rcutils_logging_default_logger_level;
}

void rcutils_logging_set_default_logger_level(int level)
{
// *INDENT-OFF* (prevent uncrustify from making unnecessary indents here)
RCUTILS_LOGGING_AUTOINIT
RCUTILS_LOGGING_AUTOINIT;
if (RCUTILS_LOG_SEVERITY_UNSET == level) {
// Restore the default
level = RCUTILS_DEFAULT_LOGGER_DEFAULT_LEVEL;
}
g_rcutils_logging_default_logger_level = level;
// *INDENT-ON*
}

int rcutils_logging_get_logger_level(const char * name)
{
RCUTILS_LOGGING_AUTOINIT
RCUTILS_LOGGING_AUTOINIT;
if (NULL == name) {
return -1;
}
Expand All @@ -383,7 +379,7 @@ int rcutils_logging_get_logger_level(const char * name)

int rcutils_logging_get_logger_leveln(const char * name, size_t name_length)
{
RCUTILS_LOGGING_AUTOINIT
RCUTILS_LOGGING_AUTOINIT;
if (NULL == name) {
return -1;
}
Expand Down Expand Up @@ -421,7 +417,7 @@ int rcutils_logging_get_logger_leveln(const char * name, size_t name_length)

int rcutils_logging_get_logger_effective_level(const char * name)
{
RCUTILS_LOGGING_AUTOINIT
RCUTILS_LOGGING_AUTOINIT;
if (NULL == name) {
return -1;
}
Expand Down Expand Up @@ -453,7 +449,7 @@ int rcutils_logging_get_logger_effective_level(const char * name)

rcutils_ret_t rcutils_logging_set_logger_level(const char * name, int level)
{
RCUTILS_LOGGING_AUTOINIT
RCUTILS_LOGGING_AUTOINIT;
if (NULL == name) {
RCUTILS_SET_ERROR_MSG("Invalid logger name");
return RCUTILS_RET_INVALID_ARGUMENT;
Expand Down Expand Up @@ -494,7 +490,7 @@ rcutils_ret_t rcutils_logging_set_logger_level(const char * name, int level)

bool rcutils_logging_logger_is_enabled_for(const char * name, int severity)
{
RCUTILS_LOGGING_AUTOINIT
RCUTILS_LOGGING_AUTOINIT;
int logger_level = g_rcutils_logging_default_logger_level;
if (name) {
logger_level = rcutils_logging_get_logger_effective_level(name);
Expand Down