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

Logging interface #41

Merged
merged 6 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
38 changes: 38 additions & 0 deletions rcl_logging_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.5)

project(rcl_logging_interface)

# Default to C11
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(NOT WIN32)
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake_ros REQUIRED)
find_package(rcutils REQUIRED)

add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
"$<INSTALL_INTERFACE:include>")
ament_target_dependencies(${PROJECT_NAME} INTERFACE rcutils)

install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME}
)

ament_export_include_directories(include)
ament_export_targets(${PROJECT_NAME})
ament_export_dependencies(rcutils)
ament_package()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Open Source Robotics Foundation, Inc.
// Copyright 2020 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.
Expand All @@ -12,53 +12,68 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RCL_LOGGING_LOG4CXX__LOGGING_INTERFACE_H_
#define RCL_LOGGING_LOG4CXX__LOGGING_INTERFACE_H_
#ifndef RCL_LOGGING_INTERFACE__RCL_LOGGING_INTERFACE_H_
#define RCL_LOGGING_INTERFACE__RCL_LOGGING_INTERFACE_H_

#include "rcl_logging_interface/visibility_control.h"
#include "rcutils/allocator.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "rcl_logging_log4cxx/visibility_control.h"

typedef int rcl_logging_ret_t;
typedef enum
{
RCL_LOGGING_RET_OK = 0,
RCL_LOGGING_RET_ERROR = 2,
RCL_LOGGING_RET_CONFIG_FILE_DOESNT_EXIST = 21,
RCL_LOGGING_RET_CONFIG_FILE_INVALID = 22,
} rcl_logging_ret_t;

/// Initialize log4cxx logging library.
/*
/// Initialize the external logging library.
/**
* \param[in] 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.
* \param[in] allocator The allocator to use for memory allocation. This is
* If provided, it must be a null terminated C string.
* If set to NULL or the empty string, the logging library will use defaults.
* \param[in] allocator The allocator to use for memory allocation. This is
* an rcutils_allocator_t rather than an rcl_allocator_t to ensure that the
* rcl_logging_* packages don't have a circular dependency back to rcl.
* \return RCL_LOGGING_RET_OK if initialized successfully, or
* \return RCL_LOGGING_RET_OK if initialized successfully.
* \return RCL_LOGGING_RET_ERROR if an unspecified error occurs.
* \return RCL_LOGGING_RET_CONFIG_FILE_DOESNT_EXIST if a config_file is provided
* but the file doesn't exist.
* \return RCL_LOGGING_RET_CONFIG_FILE_INVALID if a config_file is provided but
* the logging backend doesn't understand it.
*/
RCL_LOGGING_PUBLIC
rcl_logging_ret_t rcl_logging_external_initialize(
const char * config_file,
rcutils_allocator_t allocator);
RCL_LOGGING_INTERFACE_PUBLIC
RCUTILS_WARN_UNUSED
rcl_logging_ret_t
rcl_logging_external_initialize(const char * config_file, rcutils_allocator_t allocator);

/// Free the resources allocated for the log4cxx external logging system.
/// Free the resources allocated for the external logging system.
/**
* This puts the system into a state equivalent to being uninitialized.
*
* \return always RCL_LOGGING_RET_OK.
* \return RCL_LOGGING_RET_OK if successfully shutdown, or
* \return RCL_LOGGING_RET_ERROR if an unspecified error occurs.
*/
RCL_LOGGING_PUBLIC
rcl_logging_ret_t rcl_logging_external_shutdown();
RCL_LOGGING_INTERFACE_PUBLIC
RCUTILS_WARN_UNUSED
rcl_logging_ret_t
rcl_logging_external_shutdown();

/// Log a message.
/**
* \param[in] severity The severity level of the message being logged.
* \param[in] name The name of the logger, must either be a null terminated
* c string or NULL.
* C string or NULL.
* If NULL or empty the root logger will be used.
* \param[in] msg The message to be logged. Must be a null terminated c string.
* \param[in] msg The message to be logged. Must be a null terminated C string.
*/
RCL_LOGGING_PUBLIC
void rcl_logging_external_log(int severity, const char * name, const char * msg);
RCL_LOGGING_INTERFACE_PUBLIC
void
rcl_logging_external_log(int severity, const char * name, const char * msg);

/// Set the severity level for a logger.
/**
Expand All @@ -67,20 +82,17 @@ void rcl_logging_external_log(int severity, const char * name, const char * msg)
* the root logger.
*
* \param[in] name The name of the logger.
* Must be a NULL terminated c string or NULL.
* \param[in] level The severity level to be used for the specified logger. Values:
* RCUTILS_LOG_SEVERITY_DEBUG, RCUTILS_LOG_SEVERITY_UNSET, RCUTILS_LOG_SEVERITY_DEBUG,
* RCUTILS_LOG_SEVERITY_INFO, RCUTILS_LOG_SEVERITY_WARN, RCUTILS_LOG_SEVERITY_ERROR,
* RCUTILS_LOG_SEVERITY_FATAL
* \return always RCL_LOGGING_RET_OK.
* Must be a null terminated C string or NULL.
* \param[in] level The severity level to be used for the specified logger.
* \return RCL_LOGGING_RET_OK if set successfully, or
* \return RCL_LOGGING_RET_ERROR if an unspecified error occurs.
*/
RCL_LOGGING_PUBLIC
RCL_LOGGING_INTERFACE_PUBLIC
RCUTILS_WARN_UNUSED
rcl_logging_ret_t rcl_logging_external_set_logger_level(const char * name, int level);


#ifdef __cplusplus
} /* extern "C" */
}
#endif

#endif // RCL_LOGGING_LOG4CXX__LOGGING_INTERFACE_H_
#endif // RCL_LOGGING_INTERFACE__RCL_LOGGING_INTERFACE_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2020 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_INTERFACE__VISIBILITY_CONTROL_H_
#define RCL_LOGGING_INTERFACE__VISIBILITY_CONTROL_H_

#ifdef __cplusplus
extern "C"
{
clalancette marked this conversation as resolved.
Show resolved Hide resolved
#endif

// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
// https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define RCL_LOGGING_INTERFACE_EXPORT __attribute__ ((dllexport))
#define RCL_LOGGING_INTERFACE_IMPORT __attribute__ ((dllimport))
#else
#define RCL_LOGGING_INTERFACE_EXPORT __declspec(dllexport)
#define RCL_LOGGING_INTERFACE_IMPORT __declspec(dllimport)
#endif
#ifdef RCL_LOGGING_INTERFACE_BUILDING_DLL
#define RCL_LOGGING_INTERFACE_PUBLIC RCL_LOGGING_INTERFACE_EXPORT
#else
#define RCL_LOGGING_INTERFACE_PUBLIC RCL_LOGGING_INTERFACE_IMPORT
#endif
#define RCL_LOGGING_INTERFACE_PUBLIC_TYPE RCL_LOGGING_INTERFACE_PUBLIC
#define RCL_LOGGING_INTERFACE_LOCAL
#else
#define RCL_LOGGING_INTERFACE_EXPORT __attribute__ ((visibility("default")))
#define RCL_LOGGING_INTERFACE_IMPORT
#if __GNUC__ >= 4
#define RCL_LOGGING_INTERFACE_PUBLIC __attribute__ ((visibility("default")))
#define RCL_LOGGING_INTERFACE_LOCAL __attribute__ ((visibility("hidden")))
#else
#define RCL_LOGGING_INTERFACE_PUBLIC
#define RCL_LOGGING_INTERFACE_LOCAL
#endif
#define RCL_LOGGING_INTERFACE_PUBLIC_TYPE
#endif

#ifdef __cplusplus
}
#endif

#endif // RCL_LOGGING_INTERFACE__VISIBILITY_CONTROL_H_
18 changes: 18 additions & 0 deletions rcl_logging_interface/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rcl_logging_interface</name>
<version>1.0.0</version>
<description>Interface that rcl_logging backends needs to implement.</description>
<maintainer email="[email protected]">Chris Lalancette</maintainer>
<license>Apache License 2.0</license>
<author email="[email protected]">Chris Lalancette</author>

<buildtool_depend>ament_cmake_ros</buildtool_depend>

<depend>rcutils</depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
27 changes: 7 additions & 20 deletions rcl_logging_log4cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ endif()
find_package(ament_cmake_ros REQUIRED)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(Log4cxx REQUIRED)
find_package(rcl_logging_interface REQUIRED)
find_package(rcutils REQUIRED)

include_directories(include)


if(NOT WIN32)
add_compile_options(-Wall -Wextra -Wpedantic)
else()
Expand All @@ -29,22 +27,15 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4275 /wd4251")
endif()

set(${PROJECT_NAME}_sources
src/rcl_logging_log4cxx/rcl_logging_log4cxx.cpp
)

if(NOT WIN32)
add_library(${PROJECT_NAME} ${${PROJECT_NAME}_sources})
else()
add_library(${PROJECT_NAME} STATIC ${${PROJECT_NAME}_sources})
endif()
add_library(${PROJECT_NAME} src/rcl_logging_log4cxx/rcl_logging_log4cxx.cpp)

ament_target_dependencies(${PROJECT_NAME}
Log4cxx
rcl_logging_interface
rcutils
)

target_compile_definitions(${PROJECT_NAME} PRIVATE "RCL_LOGGING_BUILDING_DLL")
target_compile_definitions(${PROJECT_NAME} PRIVATE "RCL_LOGGING_INTERFACE_BUILDING_DLL")

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
Expand All @@ -53,16 +44,12 @@ if(BUILD_TESTING)
ament_lint_auto_find_test_dependencies()
endif()

install(TARGETS ${PROJECT_NAME}
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME}
)

ament_export_include_directories(include)
ament_export_dependencies(ament_cmake)
ament_export_dependencies(ament_cmake rcl_logging_interface rcutils)
ament_export_libraries(${PROJECT_NAME} log4cxx)
ament_export_targets(${PROJECT_NAME})
ament_package()

This file was deleted.

1 change: 1 addition & 0 deletions rcl_logging_log4cxx/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<buildtool_depend>python3-empy</buildtool_depend>

<depend>log4cxx</depend>
<depend>rcl_logging_interface</depend>
<depend>rcutils</depend>

<test_depend>ament_cmake_gmock</test_depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <rcl_logging_interface/rcl_logging_interface.h>

#include <rcutils/allocator.h>
#include <rcutils/get_env.h>
#include <rcutils/logging.h>
Expand Down Expand Up @@ -62,17 +64,6 @@ static const log4cxx::LevelPtr map_external_log_level_to_library_level(int exter
return level;
}

#ifdef __cplusplus
extern "C" {
#endif

#include "rcl_logging_log4cxx/logging_interface.h"

#define RCL_LOGGING_RET_OK (0)
#define RCL_LOGGING_RET_ERROR (2)
#define RCL_LOGGING_RET_CONFIG_FILE_DOESNT_EXIST (21)
#define RCL_LOGGING_RET_CONFIG_FILE_INVALID (22)

rcl_logging_ret_t rcl_logging_external_initialize(
const char * config_file,
rcutils_allocator_t allocator)
Expand Down Expand Up @@ -177,7 +168,3 @@ rcl_logging_ret_t rcl_logging_external_set_logger_level(const char * name, int l
logger->setLevel(map_external_log_level_to_library_level(level));
return RCL_LOGGING_RET_OK;
}

#ifdef __cplusplus
} /* extern "C" */
#endif
Loading