@@ -296,9 +296,9 @@ rcutils_ret_t rcutils_logging_initialize_with_allocator(rcutils_allocator_t allo
296
296
297
297
// We load the logging configs after setting g_rcutils_logging_initialized
298
298
// to true otherwise rcutils_logging_set_logger_level will cause recursive
299
- // call to this function due to RCUTILS_LOGGING_AUTOINIT Check for the
299
+ // call to this function due to RCUTILS_LOGGING_AUTOINIT
300
300
// Check for the environment variable for selecting logging level
301
- const char * logging_config_filename ;
301
+ const char * logging_config_filename = NULL ;
302
302
ret_str = rcutils_get_env ("RCUTILS_LOGGING_CONFIG_FILE" , & logging_config_filename );
303
303
if (NULL == ret_str && strcmp (logging_config_filename , "" ) != 0 ) {
304
304
FILE * logging_config_file = fopen (logging_config_filename , "r" );
@@ -308,24 +308,45 @@ rcutils_ret_t rcutils_logging_initialize_with_allocator(rcutils_allocator_t allo
308
308
logging_config_filename );
309
309
return RCUTILS_RET_ERROR ;
310
310
}
311
- char logger_name [50 ];
312
- char severity [10 ]; // fatal error debug info warn case insensitive
313
311
314
- while (fscanf (
315
- logging_config_file , "%49[^=]=%9[^\n]\n" , logger_name ,
316
- severity ) != EOF )
317
- {
312
+ char logger_name [128 ];
313
+ char severity [10 ]; // fatal/error/debug/info/warn case-insensitive
314
+ char line [256 ]; // lines could have comments
315
+ while (fgets (line , sizeof (line ), logging_config_file )) {
316
+ // If a line start with # ignore it since it's a comment
317
+ if (line [0 ] == '#' ) {
318
+ continue ;
319
+ }
320
+ if (sscanf (
321
+ line , "%127[^=]=%9[^\t\n ]\n" , logger_name ,
322
+ severity ) != 2 )
323
+ {
324
+ RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING (
325
+ "Failed to parse line in logging config file [%s]: %s" , logging_config_filename , line );
326
+ fclose (logging_config_file );
327
+ return RCUTILS_RET_ERROR ;
328
+ }
318
329
int severity_level ;
319
330
if (RCUTILS_RET_OK != rcutils_logging_severity_level_from_string (
320
331
severity , g_rcutils_logging_allocator , & severity_level ))
321
332
{
322
- RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING (
323
- "Logger has an invalid severity level: %s\n" , severity );
333
+ RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING (
334
+ "Logger has an invalid severity level: %s" , severity );
335
+ fclose (logging_config_file );
324
336
return RCUTILS_RET_ERROR ;
325
337
}
326
- if (RCUTILS_RET_OK != rcutils_logging_set_logger_level (logger_name , severity_level )) {
327
- RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING (
328
- "Failed to set severity level: %s for logger '%s'\n" , severity , logger_name );
338
+ // Special name for setting the default logger level
339
+ if (strcmp (logger_name , "default_logger_level" ) == 0 ) {
340
+ g_rcutils_logging_default_logger_level = severity_level ;
341
+ // NOLINTNEXTLINE
342
+ } else if (
343
+ RCUTILS_RET_OK !=
344
+ rcutils_logging_set_logger_level (logger_name , severity_level ))
345
+ {
346
+ RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING (
347
+ "Failed to set severity level: %s for logger '%s'" , severity , logger_name );
348
+ fclose (logging_config_file );
349
+ return RCUTILS_RET_ERROR ;
329
350
}
330
351
}
331
352
0 commit comments