Skip to content

Commit

Permalink
Set default logger level from command line (#256)
Browse files Browse the repository at this point in the history
* Set default logger level from command line

* Return INVALID_REMAP_RULE

* Add tests

* Do string parsing in rcutils

* Set log level after parsing all arguments

Less convenient but seems cleaner

* Document log arg format, custom return code

* Rename function

* Rename argument

* Refactor argument parsing after rebasing to include param files

* Renaming from param files support

* Doc fixup

* __log -> __log_level

* Use RCUTILS_SAFE_FWRITE_TO_STDERR on bad alloc

* doc fixup

* doc fixup

* Document behaviour if multiple __log_level rules found

* Update docblock formatting

* Label all documentation in arguments.c as internal
  • Loading branch information
dhood authored Jun 12, 2018
1 parent 9a84b2d commit 6c785ff
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 57 deletions.
4 changes: 4 additions & 0 deletions rcl/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ EXPAND_ONLY_PREDEF = YES
PREDEFINED += RCL_PUBLIC=
PREDEFINED += RCL_WARN_UNUSED=

# Uncomment to generate internal documentation.
ENABLED_SECTIONS = INTERNAL
INPUT += ./src/rcl/arguments.c

# Tag files that do not exist will produce a warning and cross-project linking will not work.
TAGFILES += "../../../../doxygen_tag_files/cppreference-doxygen-web.tag.xml=http://en.cppreference.com/w/"
# Consider changing "latest" to the version you want to reference (e.g. beta1 or 1.0.0)
Expand Down
9 changes: 9 additions & 0 deletions rcl/include/rcl/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ typedef struct rcl_arguments_t
struct rcl_arguments_impl_t * impl;
} rcl_arguments_t;

#define RCL_LOG_LEVEL_ARG_RULE "__log_level:="
#define RCL_PARAM_FILE_ARG_RULE "__params:="

/// Return a rcl_node_t struct with members initialized to `NULL`.
RCL_PUBLIC
RCL_WARN_UNUSED
Expand All @@ -52,6 +55,12 @@ rcl_get_zero_initialized_arguments(void);
* Successfully parsed remap rules are stored in the order they were given in `argv`.
* If given arguments `{"__ns:=/foo", "__ns:=/bar"}` then the namespace used by nodes in this
* process will be `/foo` and not `/bar`.
*
* The default log level will be parsed as `__log_level:=level`, where `level` is a name
* representing one of the log levels in the `RCUTILS_LOG_SEVERITY` enum, e.g. `info`, `debug`,
* `warn`, not case sensitive.
* If multiple of these rules are found, the last one parsed will be used.
*
* \sa rcl_remap_topic_name()
* \sa rcl_remap_service_name()
* \sa rcl_remap_node_name()
Expand Down
2 changes: 2 additions & 0 deletions rcl/include/rcl/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,7 @@ typedef rmw_ret_t rcl_ret_t;
#define RCL_RET_WRONG_LEXEME 1002
/// Argument is not a valid parameter rule
#define RCL_RET_INVALID_PARAM_RULE 1010
/// Argument is not a valid log level rule
#define RCL_RET_INVALID_LOG_LEVEL_RULE 1020

#endif // RCL__TYPES_H_
Loading

0 comments on commit 6c785ff

Please sign in to comment.