Repository navigation
add logging API and macros #138
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0cb1c1f
add logging API and macros
dirk-thomas 33b21de
rename RclLogLocation to rcl_log_location_t
dirk-thomas 1842923
rename RclLogFunction to rcl_logging_output_handler_t
dirk-thomas c1d727e
add 'generated from' line
dirk-thomas 420753d
wrap long lines
dirk-thomas 44a7023
fix checking return value of get_now
dirk-thomas 2019aa2
support messages longer than 1024 bytes
dirk-thomas adfe5a5
add attributes to docblocks
dirk-thomas 8bf127a
clone va_list
dirk-thomas 916bb12
add test for long messages
dirk-thomas 6e43b40
move init assignment
dirk-thomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| // 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/visibility_control.h" | ||
|
|
||
| #if __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /// The flag if the logging system has been initialized. | ||
| RCL_PUBLIC | ||
| extern bool g_rcl_logging_initialized; | ||
|
|
||
| /// Initialize the logging system. | ||
| /** | ||
| * The function is called automatically when using the logging macros. | ||
| * | ||
| * <hr> | ||
| * Attribute | Adherence | ||
| * ------------------ | ------------- | ||
| * Allocates Memory | No | ||
| * Thread-Safe | No | ||
| * Uses Atomics | No | ||
| * Lock-Free | Yes | ||
| */ | ||
| RCL_PUBLIC | ||
| void rcl_logging_initialize(); | ||
|
|
||
| /// The structure identifying the caller location in the source code. | ||
| typedef struct rcl_log_location_t | ||
| { | ||
| /// The name of the function containing the log call. | ||
| const char * function_name; | ||
| /// The name of the source file containing the log call. | ||
| const char * file_name; | ||
| /// The line number containing the log call. | ||
| size_t line_number; | ||
| } rcl_log_location_t; | ||
|
|
||
| /// The severity levels of log message. | ||
| enum RCL_LOG_SEVERITY | ||
| { | ||
| RCL_LOG_SEVERITY_DEBUG = 0, ///< The debug log level | ||
| RCL_LOG_SEVERITY_INFO = 1, ///< The info log level | ||
| RCL_LOG_SEVERITY_WARN = 2, ///< The warn log level | ||
| RCL_LOG_SEVERITY_ERROR = 3, ///< The error log level | ||
| RCL_LOG_SEVERITY_FATAL = 4, ///< The fatal log level | ||
| }; | ||
|
|
||
| /// The function signature to log messages. | ||
| /** | ||
| * \param The pointer to the location struct | ||
| * \param The severity level | ||
| * \param The name of the logger | ||
| * \param The format string | ||
| * \param The variable argument list | ||
| */ | ||
| typedef void (* rcl_logging_output_handler_t)( | ||
| rcl_log_location_t *, // location | ||
| int, // severity | ||
| const char *, // name | ||
| const char *, // format | ||
| va_list * // args | ||
| ); | ||
|
|
||
| /// The function pointer of the current output handler. | ||
| RCL_PUBLIC | ||
| extern rcl_logging_output_handler_t g_rcl_logging_output_handler; | ||
|
|
||
| /// Get the current output handler. | ||
| /** | ||
| * <hr> | ||
| * Attribute | Adherence | ||
| * ------------------ | ------------- | ||
| * Allocates Memory | No | ||
| * Thread-Safe | No | ||
| * Uses Atomics | No | ||
| * Lock-Free | Yes | ||
| * | ||
| * \return The function pointer of the current output handler. | ||
| */ | ||
| RCL_PUBLIC | ||
| rcl_logging_output_handler_t rcl_logging_get_output_handler(); | ||
|
|
||
| /// Set the current output handler. | ||
| /** | ||
| * <hr> | ||
| * Attribute | Adherence | ||
| * ------------------ | ------------- | ||
| * Allocates Memory | No | ||
| * Thread-Safe | No | ||
| * Uses Atomics | No | ||
| * Lock-Free | Yes | ||
| * | ||
| * \param function The function pointer of the output handler to be used. | ||
| */ | ||
| RCL_PUBLIC | ||
| void rcl_logging_set_output_handler(rcl_logging_output_handler_t function); | ||
|
|
||
| /// 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. | ||
| * | ||
| * \param severity The global severity threshold to be used. | ||
| */ | ||
| RCL_PUBLIC | ||
| extern int g_rcl_logging_severity_threshold; | ||
|
|
||
| /// Get the global severity threshold. | ||
| /** | ||
| * <hr> | ||
| * Attribute | Adherence | ||
| * ------------------ | ------------- | ||
| * Allocates Memory | No | ||
| * Thread-Safe | No | ||
| * Uses Atomics | No | ||
| * Lock-Free | Yes | ||
| * | ||
| * \return The severity threshold. | ||
| */ | ||
| RCL_PUBLIC | ||
| int rcl_logging_get_severity_threshold(); | ||
|
|
||
| /// Set the global severity threshold. | ||
| /** | ||
| * <hr> | ||
| * Attribute | Adherence | ||
| * ------------------ | ------------- | ||
| * Allocates Memory | No | ||
| * Thread-Safe | No | ||
| * Uses Atomics | No | ||
| * Lock-Free | Yes | ||
| * | ||
| * \param severity The severity threshold to be used. | ||
| */ | ||
| RCL_PUBLIC | ||
| void rcl_logging_set_severity_threshold(int severity); | ||
|
|
||
| /// Log a message. | ||
| /** | ||
| * The attributes of this function are also being influenced by the currently | ||
| * set output handler. | ||
| * | ||
| * <hr> | ||
| * Attribute | Adherence | ||
| * ------------------ | ------------- | ||
| * Allocates Memory | No | ||
| * Thread-Safe | No | ||
| * Uses Atomics | No | ||
| * Lock-Free | Yes | ||
| * | ||
| * \param location The pointer to the location struct | ||
| * \param severity The severity level | ||
| * \param name The name of the logger | ||
| * \param format The format string | ||
| * \param ... The variable arguments | ||
| */ | ||
| RCL_PUBLIC | ||
| void rcl_log( | ||
| rcl_log_location_t * location, | ||
| int severity, | ||
| const char * name, | ||
| const char * format, | ||
| ...); | ||
|
|
||
| /// 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. | ||
| * | ||
| * <hr> | ||
| * 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 | ||
| * | ||
| * \param location The pointer to the location struct | ||
| * \param severity The severity level | ||
| * \param name The name of the logger | ||
| * \param format The format string | ||
| * \param args The variable argument list | ||
| */ | ||
| RCL_PUBLIC | ||
| void rcl_logging_console_output_handler( | ||
| rcl_log_location_t * location, | ||
| int severity, const char * name, const char * format, va_list * args); | ||
|
|
||
| #if __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif // RCL__LOGGING_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be part of the sources?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the file is generated this makes sure the generation happens before the library is being compiled.