Skip to content

Commit 059f8e1

Browse files
committed
Moving the external logger library from rcutils into rcl. Also automatic uncrustify.
1 parent cf4d247 commit 059f8e1

File tree

11 files changed

+358
-28
lines changed

11 files changed

+358
-28
lines changed

‎rcl/CMakeLists.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ find_package(rosidl_generator_c REQUIRED)
1212

1313
include_directories(include)
1414

15+
include(cmake/get_default_rc_logging_implementation.cmake)
16+
get_default_rc_logging_implementation(RC_LOGGING_IMPL)
17+
1518
# Default to C11
1619
if(NOT CMAKE_C_STANDARD)
1720
set(CMAKE_C_STANDARD 11)
@@ -35,6 +38,7 @@ set(${PROJECT_NAME}_sources
3538
src/rcl/guard_condition.c
3639
src/rcl/lexer.c
3740
src/rcl/lexer_lookahead.c
41+
src/rcl/logging.c
3842
src/rcl/node.c
3943
src/rcl/publisher.c
4044
src/rcl/rcl.c
@@ -56,6 +60,7 @@ ament_target_dependencies(${PROJECT_NAME}
5660
"rmw"
5761
"rcutils"
5862
"rosidl_generator_c"
63+
${RC_LOGGING_IMPL}
5964
)
6065

6166
# Causes the visibility macros to use dllexport rather than dllimport,
@@ -84,6 +89,7 @@ ament_export_dependencies(rmw_implementation)
8489
ament_export_dependencies(rmw)
8590
ament_export_dependencies(rcutils)
8691
ament_export_dependencies(rosidl_generator_c)
92+
ament_export_dependencies(${RC_LOGGING_IMPL})
8793

8894
if(BUILD_TESTING)
8995
find_package(ament_lint_auto REQUIRED)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2018 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+
#
16+
# Get the package name of the default logging implementation.
17+
#
18+
# Either selecting it using the variable RC_LOGGING_IMPLEMENTATION or
19+
# choosing a default from the available implementations.
20+
#
21+
# :param var: the output variable name containing the package name
22+
# :type var: string
23+
#
24+
macro(get_default_rc_logging_implementation var)
25+
26+
# if logging implementation already specified or RC_LOGGING_IMPLEMENTATION environment variable
27+
# is set then use that, otherwise default to using rc_logging_log4cxx
28+
if(NOT "${RC_LOGGING_IMPLEMENTATION}" STREQUAL "")
29+
set(_logging_implementation "${RC_LOGGING_IMPLEMENTATION}")
30+
elseif(NOT "$ENV{RC_LOGGING_IMPLEMENTATION}" STREQUAL "")
31+
set(_logging_implementation "$ENV{RC_LOGGING_IMPLEMENTATION}")
32+
else()
33+
set(_logging_implementation rc_logging_log4cxx)
34+
endif()
35+
36+
# persist implementation decision in cache
37+
# if it was not determined dynamically
38+
set(
39+
RC_LOGGING_IMPLEMENTATION "${_logging_implementation}"
40+
CACHE STRING "Select ROS middleware implementation to link against" FORCE
41+
)
42+
43+
find_package("${_logging_implementation}" REQUIRED)
44+
45+
set(${var} ${_logging_implementation})
46+
endmacro()

‎rcl/include/rcl/arguments.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ typedef struct rcl_arguments_t
3434
struct rcl_arguments_impl_t * impl;
3535
} rcl_arguments_t;
3636

37-
#define RCL_LOG_LEVEL_ARG_RULE "__log_level:="
38-
#define RCL_EXTERNAL_LOG_CONFIG_ARG_RULE "__log_config_file:="
39-
#define RCL_LOG_DISABLE_STDOUT_ARG_RULE "__log_disable_stdout:="
40-
#define RCL_LOG_DISABLE_ROSOUT_ARG_RULE "__log_disable_rosout:="
41-
#define RCL_LOG_DISABLE_EXT_LIB_ARG_RULE "__log_disable_external_lib:="
42-
#define RCL_PARAM_FILE_ARG_RULE "__params:="
37+
#define RCL_LOG_LEVEL_ARG_RULE "__log_level:="
38+
#define RCL_EXTERNAL_LOG_CONFIG_ARG_RULE "__log_config_file:="
39+
#define RCL_LOG_DISABLE_STDOUT_ARG_RULE "__log_disable_stdout:="
40+
#define RCL_LOG_DISABLE_ROSOUT_ARG_RULE "__log_disable_rosout:="
41+
#define RCL_LOG_DISABLE_EXT_LIB_ARG_RULE "__log_disable_external_lib:="
42+
#define RCL_PARAM_FILE_ARG_RULE "__params:="
4343

4444
/// Return a rcl_node_t struct with members initialized to `NULL`.
4545
RCL_PUBLIC

‎rcl/include/rcl/logging.h‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 RCL__LOGGING_H_
16+
#define RCL__LOGGING_H_
17+
18+
#include <stdarg.h>
19+
#include <stdbool.h>
20+
#include <stdio.h>
21+
22+
#include "rcl/allocator.h"
23+
#include "rcl/arguments.h"
24+
#include "rcl/error_handling.h"
25+
#include "rcl/types.h"
26+
#include "rcl/visibility_control.h"
27+
28+
#ifdef __cplusplus
29+
extern "C"
30+
{
31+
#endif
32+
33+
34+
/// Configures the logging system.
35+
/**
36+
* This function should be called during the ROS initialization process. It will
37+
* add the enabled log output appenders to the root logger.
38+
*
39+
* <hr>
40+
* Attribute | Adherence
41+
* ------------------ | -------------
42+
* Allocates Memory | No
43+
* Thread-Safe | No
44+
* Uses Atomics | No
45+
* Lock-Free | Yes
46+
*
47+
* \param global_args The global arguments for the system
48+
* \return `RCL_RET_OK` if successful.
49+
* \return `RCL_RET_ERR` if a general error occurs
50+
*/
51+
RCL_PUBLIC
52+
rcl_ret_t rcl_logging_configure(const rcl_arguments_t * global_args);
53+
54+
#ifdef __cplusplus
55+
}
56+
#endif
57+
58+
#endif // RCL__LOGGING_H_
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2018 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 RCL__LOGGING_EXTERNAL_INTERFACE_H_
16+
#define RCL__LOGGING_EXTERNAL_INTERFACE_H_
17+
18+
#include <stdarg.h>
19+
#include "rcl/types.h"
20+
#include "rcl/visibility_control.h"
21+
22+
23+
/**
24+
* \brief Initializes the external logging library.
25+
*
26+
* \param config_file The location of a config file that the external logging library should use to configure itself.
27+
* If no config file is provided this will be set to an empty string. Must be a NULL terminated c string.
28+
* \return RC_EXTERNAL_LOGGING_RET_OK if initialized successfully or an error code if not.
29+
*/
30+
RCL_PUBLIC
31+
rcl_ret_t rcl_logging_external_initialize(const char * config_file);
32+
33+
/**
34+
* \brief Free the resources allocated for the external logging system.
35+
* This puts the system into a state equivalent to being uninitialized
36+
*
37+
* \return RC_EXTERNAL_LOGGING_RET_OK if successfully shutdown or an error code if not.
38+
*/
39+
RCL_PUBLIC
40+
rcl_ret_t rcl_logging_external_shutdown();
41+
42+
/**
43+
* \brief Logs a message
44+
*
45+
* \param severity The severity level of the message being logged
46+
* \param name The name of the logger, must be a null terminated c string or NULL. If NULL or empty the root logger will
47+
* be used.
48+
* \param msg The message to be logged. Must be a null terminated c string.
49+
*/
50+
RCL_PUBLIC
51+
void rcl_logging_external_log(int severity, const char * name, const char * msg);
52+
53+
54+
/**
55+
* \brief Set the severity level for a logger.
56+
* Sets the severity level for the specified logger. If the name provided is an empty string or NULL it will change the
57+
* level of the root logger.
58+
*
59+
* \param name The name of the logger. Must be a NULL terminated c string or NULL.
60+
* \param level - The severity level to be used for the specified logger
61+
* \return RC_EXTERNAL_LOGGING_RET_OK if set successfully or an error code if not.
62+
*/
63+
RCL_PUBLIC
64+
rcl_ret_t rcl_logging_external_set_logger_level(const char * name, int level);
65+
66+
#endif // RCL__LOGGING_EXTERNAL_INTERFACE_H_

‎rcl/include/rcl/macros.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ extern "C"
2727
# define RCL_WARN_UNUSED _Check_return_
2828
#endif
2929

30+
#define RCL_UNUSED(x) (void)(x)
31+
3032
#ifdef __cplusplus
3133
}
3234
#endif

‎rcl/package.xml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3-
<package format="2">
3+
<package format="3">
44
<name>rcl</name>
55
<version>0.6.0</version>
66
<description>The ROS client library common implementation.
@@ -27,6 +27,8 @@
2727

2828
<depend>rmw_implementation</depend>
2929

30+
<group_depend>rc_logging_packages</group_depend>
31+
3032
<test_depend>ament_cmake_gtest</test_depend>
3133
<test_depend>ament_cmake_pytest</test_depend>
3234
<test_depend>ament_lint_auto</test_depend>

‎rcl/src/rcl/arguments.c‎

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ rcl_parse_arguments(
261261
}
262262
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
263263
"Couldn't parse arg %d (%s) as parameter file rule. Error: %s", i, argv[i],
264-
rcl_get_error_string());
264+
rcl_get_error_string().str);
265265
rcl_reset_error();
266266

267267
// Attempt to parse argument as remap rule
@@ -272,7 +272,8 @@ rcl_parse_arguments(
272272
continue;
273273
}
274274
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
275-
"Couldn't parse arg %d (%s) as remap rule. Error: %s", i, argv[i], rcl_get_error_string());
275+
"Couldn't parse arg %d (%s) as remap rule. Error: %s", i, argv[i],
276+
rcl_get_error_string().str);
276277
rcl_reset_error();
277278

278279
// Attempt to parse argument as log level configuration
@@ -283,43 +284,54 @@ rcl_parse_arguments(
283284
}
284285
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
285286
"Couldn't parse arg %d (%s) as log level rule. Error: %s", i, argv[i],
286-
rcl_get_error_string());
287+
rcl_get_error_string().str);
287288
rcl_reset_error();
288289

289290
// Attempt to parse argument as log configuration file
290-
if (RCL_RET_OK == _rcl_parse_external_log_config_file(argv[i], allocator, &args_impl->external_log_config_file)) {
291+
rcl_ret_t ret = _rcl_parse_external_log_config_file(argv[i], allocator,
292+
&args_impl->external_log_config_file);
293+
if (RCL_RET_OK == ret) {
291294
continue;
292295
}
293296
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
294297
"Couldn't parse arg %d (%s) as log config rule. Error: %s", i, argv[i],
295-
rcl_get_error_string());
298+
rcl_get_error_string().str);
296299
rcl_reset_error();
297300

298301
// Attempt to parse argument as log_stdout_disabled
299-
if (RCL_RET_OK == _rcl_parse_bool_arg(argv[i], RCL_LOG_DISABLE_STDOUT_ARG_RULE, &args_impl->log_stdout_disabled)) {
302+
if (RCL_RET_OK ==
303+
_rcl_parse_bool_arg(argv[i], RCL_LOG_DISABLE_STDOUT_ARG_RULE,
304+
&args_impl->log_stdout_disabled))
305+
{
300306
continue;
301307
}
302308
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
303309
"Couldn't parse arg %d (%s) as log_stdout_disabled rule. Error: %s", i, argv[i],
304-
rcl_get_error_string());
310+
rcl_get_error_string().str);
305311
rcl_reset_error();
306312

307313
// Attempt to parse argument as log_rosout_disabled
308-
if (RCL_RET_OK == _rcl_parse_bool_arg(argv[i], RCL_LOG_DISABLE_ROSOUT_ARG_RULE, &args_impl->log_rosout_disabled)) {
314+
if (RCL_RET_OK ==
315+
_rcl_parse_bool_arg(argv[i], RCL_LOG_DISABLE_ROSOUT_ARG_RULE,
316+
&args_impl->log_rosout_disabled))
317+
{
309318
continue;
310319
}
311320
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
312321
"Couldn't parse arg %d (%s) as log_rosout_disabled rule. Error: %s", i, argv[i],
313-
rcl_get_error_string());
322+
rcl_get_error_string().str);
314323
rcl_reset_error();
315324

316325
// Attempt to parse argument as log_ext_lib_disabled
317-
if (RCL_RET_OK == _rcl_parse_bool_arg(argv[i], RCL_LOG_DISABLE_EXT_LIB_ARG_RULE, &args_impl->log_ext_lib_disabled)) {
326+
if (RCL_RET_OK ==
327+
_rcl_parse_bool_arg(argv[i], RCL_LOG_DISABLE_EXT_LIB_ARG_RULE,
328+
&args_impl->log_ext_lib_disabled))
329+
{
318330
continue;
319331
}
320332
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
321333
"Couldn't parse arg %d (%s) as log_ext_lib_disabled rule. Error: %s", i, argv[i],
322-
rcl_get_error_string());
334+
rcl_get_error_string().str);
323335
rcl_reset_error();
324336

325337

@@ -1170,10 +1182,10 @@ _rcl_parse_external_log_config_file(
11701182
{
11711183
RCL_CHECK_ARGUMENT_FOR_NULL(arg, RCL_RET_INVALID_ARGUMENT);
11721184

1173-
const size_t param_prefix_len = sizeof(RCL_EXTERNAL_LOG_CONFIG_ARG_RULE);
1185+
const size_t param_prefix_len = sizeof(RCL_EXTERNAL_LOG_CONFIG_ARG_RULE) - 1;
11741186
if (strncmp(RCL_EXTERNAL_LOG_CONFIG_ARG_RULE, arg, param_prefix_len) == 0) {
11751187
size_t outlen = strlen(arg) - param_prefix_len;
1176-
log_config_file = allocator.allocate(sizeof(char) * (outlen + 1), allocator.state);
1188+
*log_config_file = allocator.allocate(sizeof(char) * (outlen + 1), allocator.state);
11771189
if (NULL == log_config_file) {
11781190
RCUTILS_SAFE_FWRITE_TO_STDERR("Failed to allocate memory for parameters file path\n");
11791191
return RCL_RET_BAD_ALLOC;
@@ -1213,8 +1225,8 @@ _atob(
12131225
{
12141226
RCL_CHECK_ARGUMENT_FOR_NULL(str, RCL_RET_INVALID_ARGUMENT);
12151227
RCL_CHECK_ARGUMENT_FOR_NULL(val, RCL_RET_INVALID_ARGUMENT);
1216-
const char * true_values[] = {"y", "Y", "yes", "Yes", "t", "T", "true", "True", "1" };
1217-
const char * false_values[] = {"n", "N", "no", "No", "f", "F", "false", "False", "0" };
1228+
const char * true_values[] = {"y", "Y", "yes", "Yes", "t", "T", "true", "True", "1"};
1229+
const char * false_values[] = {"n", "N", "no", "No", "f", "F", "false", "False", "0"};
12181230

12191231
for (size_t idx = 0; idx < sizeof(true_values) / sizeof(char *); idx++) {
12201232
if (0 == strncmp(true_values[idx], str, strlen(true_values[idx]))) {

‎rcl/src/rcl/arguments_impl.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ typedef struct rcl_arguments_impl_t
4646
int log_level;
4747
/// A file used to configure the external logging library
4848
char * external_log_config_file;
49+
/// A boolean value indicating if the standard out handler should be used for log output
4950
bool log_stdout_disabled;
51+
/// A boolean value indicating if the rosout topic handler should be used for log output
5052
bool log_rosout_disabled;
53+
/// A boolean value indicating if the external lib handler should be used for log output
5154
bool log_ext_lib_disabled;
5255

5356
/// Allocator used to allocate objects in this struct

0 commit comments

Comments
 (0)