-
Notifications
You must be signed in to change notification settings - Fork 123
Add option to set logger severity level using a config file #347
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
base: rolling
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -293,6 +293,44 @@ rcutils_ret_t rcutils_logging_initialize_with_allocator(rcutils_allocator_t allo | |
| } | ||
|
|
||
| g_rcutils_logging_initialized = true; | ||
|
|
||
| // We load the logging configs after setting g_rcutils_logging_initialized | ||
| // to true otherwise rcutils_logging_set_logger_level will cause recursive | ||
| // call to this function due to RCUTILS_LOGGING_AUTOINIT Check for the | ||
| // Check for the environment variable for selecting logging level | ||
| const char * logging_config_filename; | ||
| ret_str = rcutils_get_env("RCUTILS_LOGGING_CONFIG_FILE", &logging_config_filename); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about define for |
||
| if (NULL == ret_str && strcmp(logging_config_filename, "") != 0) { | ||
| FILE * logging_config_file = fopen(logging_config_filename, "r"); | ||
| if (NULL == logging_config_file) { | ||
| RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING( | ||
| "Failed to open logging config file `[%s]`.", | ||
| logging_config_filename); | ||
| return RCUTILS_RET_ERROR; | ||
| } | ||
| char logger_name[50]; | ||
| char severity[10]; // fatal error debug info warn case insensitive | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about allocate memory dynamically? I think that how it is done when parsing the arguments logging level.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I did some googling, looks like having scanf allocate memory is a posix extension which mean that it may not work on windows (I'm not sure) |
||
|
|
||
| while (fscanf( | ||
| logging_config_file, "%49[^=]=%9[^\n]\n", logger_name, | ||
| severity) != EOF) | ||
| { | ||
| int severity_level; | ||
| if (RCUTILS_RET_OK != rcutils_logging_severity_level_from_string( | ||
| severity, g_rcutils_logging_allocator, &severity_level)) | ||
| { | ||
| RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING( | ||
| "Logger has an invalid severity level: %s\n", severity); | ||
| return RCUTILS_RET_ERROR; | ||
| } | ||
| if (RCUTILS_RET_OK != rcutils_logging_set_logger_level(logger_name, severity_level)) { | ||
| RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING( | ||
| "Failed to set severity level: %s for logger '%s'\n", severity, logger_name); | ||
|
JafarAbdi marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| fclose(logging_config_file); | ||
|
JafarAbdi marked this conversation as resolved.
|
||
| } | ||
| } | ||
| return ret; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.