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

Adding new cli parameters for configuring the logging. #327

Merged
merged 12 commits into from
Dec 7, 2018
6 changes: 6 additions & 0 deletions rcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ find_package(rosidl_generator_c REQUIRED)

include_directories(include)

include(cmake/get_default_rc_logging_implementation.cmake)
get_default_rc_logging_implementation(RC_LOGGING_IMPL)

# Default to C11
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
Expand All @@ -38,6 +41,7 @@ set(${PROJECT_NAME}_sources
src/rcl/init_options.c
src/rcl/lexer.c
src/rcl/lexer_lookahead.c
src/rcl/logging.c
src/rcl/node.c
src/rcl/publisher.c
src/rcl/remap.c
Expand All @@ -58,6 +62,7 @@ ament_target_dependencies(${PROJECT_NAME}
"rmw"
"rcutils"
"rosidl_generator_c"
${RC_LOGGING_IMPL}
)

# Causes the visibility macros to use dllexport rather than dllimport,
Expand Down Expand Up @@ -86,6 +91,7 @@ ament_export_dependencies(rmw_implementation)
ament_export_dependencies(rmw)
ament_export_dependencies(rcutils)
ament_export_dependencies(rosidl_generator_c)
ament_export_dependencies(${RC_LOGGING_IMPL})

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
Expand Down
46 changes: 46 additions & 0 deletions rcl/cmake/get_default_rc_logging_implementation.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2018 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# Get the package name of the default logging implementation.
#
# Either selecting it using the variable RC_LOGGING_IMPLEMENTATION or
# choosing a default from the available implementations.
#
# :param var: the output variable name containing the package name
# :type var: string
#
macro(get_default_rc_logging_implementation var)

# if logging implementation already specified or RC_LOGGING_IMPLEMENTATION environment variable
# is set then use that, otherwise default to using rc_logging_noop
if(NOT "${RC_LOGGING_IMPLEMENTATION}" STREQUAL "")
set(_logging_implementation "${RC_LOGGING_IMPLEMENTATION}")
elseif(NOT "$ENV{RC_LOGGING_IMPLEMENTATION}" STREQUAL "")
set(_logging_implementation "$ENV{RC_LOGGING_IMPLEMENTATION}")
else()
set(_logging_implementation rc_logging_noop)
endif()

# persist implementation decision in cache
# if it was not determined dynamically
set(
RC_LOGGING_IMPLEMENTATION "${_logging_implementation}"
CACHE STRING "Select ROS middleware implementation to link against" FORCE
)

find_package("${_logging_implementation}" REQUIRED)

set(${var} ${_logging_implementation})
endmacro()
4 changes: 4 additions & 0 deletions rcl/include/rcl/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ typedef struct rcl_arguments_t
} rcl_arguments_t;

#define RCL_LOG_LEVEL_ARG_RULE "__log_level:="
#define RCL_EXTERNAL_LOG_CONFIG_ARG_RULE "__log_config_file:="
#define RCL_LOG_DISABLE_STDOUT_ARG_RULE "__log_disable_stdout:="
#define RCL_LOG_DISABLE_ROSOUT_ARG_RULE "__log_disable_rosout:="
#define RCL_LOG_DISABLE_EXT_LIB_ARG_RULE "__log_disable_external_lib:="
#define RCL_PARAM_FILE_ARG_RULE "__params:="

/// Return a rcl_node_t struct with members initialized to `NULL`.
Expand Down
58 changes: 58 additions & 0 deletions rcl/include/rcl/logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2017 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RCL__LOGGING_H_
#define RCL__LOGGING_H_

#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>

#include "rcl/allocator.h"
#include "rcl/arguments.h"
#include "rcl/error_handling.h"
#include "rcl/types.h"
#include "rcl/visibility_control.h"

#ifdef __cplusplus
extern "C"
{
#endif


/// Configures the logging system.
/**
* This function should be called during the ROS initialization process. It will
* add the enabled log output appenders to the root logger.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | Yes
*
* \param global_args The global arguments for the system
* \return `RCL_RET_OK` if successful.
* \return `RCL_RET_ERR` if a general error occurs
*/
RCL_PUBLIC
rcl_ret_t rcl_logging_configure(const rcl_arguments_t * global_args);

#ifdef __cplusplus
}
#endif

#endif // RCL__LOGGING_H_
66 changes: 66 additions & 0 deletions rcl/include/rcl/logging_external_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2018 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RCL__LOGGING_EXTERNAL_INTERFACE_H_
#define RCL__LOGGING_EXTERNAL_INTERFACE_H_

#include <stdarg.h>
#include "rcl/types.h"
#include "rcl/visibility_control.h"


/**
* \brief Initializes the external logging library.
*
* \param config_file The location of a config file that the external logging library should use to configure itself.
* If no config file is provided this will be set to an empty string. Must be a NULL terminated c string.
* \return RC_EXTERNAL_LOGGING_RET_OK if initialized successfully or an error code if not.
*/
RCL_PUBLIC
rcl_ret_t rcl_logging_external_initialize(const char * config_file);

/**
* \brief Free the resources allocated for the external logging system.
* This puts the system into a state equivalent to being uninitialized
*
* \return RC_EXTERNAL_LOGGING_RET_OK if successfully shutdown or an error code if not.
*/
RCL_PUBLIC
rcl_ret_t rcl_logging_external_shutdown();

/**
* \brief Logs a message
*
* \param severity The severity level of the message being logged
* \param name The name of the logger, must be a null terminated c string or NULL. If NULL or empty the root logger will
* be used.
* \param msg The message to be logged. Must be a null terminated c string.
*/
RCL_PUBLIC
void rcl_logging_external_log(int severity, const char * name, const char * msg);


/**
* \brief Set the severity level for a logger.
* Sets the severity level for the specified logger. If the name provided is an empty string or NULL it will change the
* level of the root logger.
*
* \param name The name of the logger. Must be a NULL terminated c string or NULL.
* \param level - The severity level to be used for the specified logger
* \return RC_EXTERNAL_LOGGING_RET_OK if set successfully or an error code if not.
*/
RCL_PUBLIC
rcl_ret_t rcl_logging_external_set_logger_level(const char * name, int level);

#endif // RCL__LOGGING_EXTERNAL_INTERFACE_H_
2 changes: 2 additions & 0 deletions rcl/include/rcl/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ extern "C"
# define RCL_WARN_UNUSED _Check_return_
#endif

#define RCL_UNUSED(x) (void)(x)

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion rcl/package.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
<package format="2">
<package format="3">
<name>rcl</name>
<version>0.6.0</version>
<description>The ROS client library common implementation.
Expand All @@ -27,6 +27,8 @@

<depend>rmw_implementation</depend>

<group_depend>rc_logging_packages</group_depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_lint_auto</test_depend>
Expand Down
Loading