From 9ae1e0f04fc3bac70720e7a0d23d859c57c79985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Arenh=C3=B6vel?= Date: Fri, 29 May 2026 04:53:31 +0200 Subject: [PATCH] feat(logger): append topics defined in logger_topics.txt instead of replacing all (#27462) * feat(logger): append topics defined in logger_topics.txt instead of replacing logging profile * docs(logger): Explain how logger_topics.txt topics are being used * refactor(logger): squash initialize functions into a single one * docs(docs): Subedit --------- Co-authored-by: Hamish Willee Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> --- docs/en/dev_log/logging.md | 26 ++++++++++++++++---------- src/modules/logger/logged_topics.cpp | 26 ++++++++++++-------------- src/modules/logger/logged_topics.h | 8 +++----- src/modules/logger/logger.cpp | 5 ----- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/docs/en/dev_log/logging.md b/docs/en/dev_log/logging.md index cb494f85d9..f046b8fec0 100644 --- a/docs/en/dev_log/logging.md +++ b/docs/en/dev_log/logging.md @@ -52,21 +52,27 @@ This allows, for example, logging of your own uORB topics. ### SD Card Configuration -Separately, the list of logged topics can also be customized with a file on the SD card. -Create a file `etc/logging/logger_topics.txt` on the card with a list of topics (For SITL, it's `build/px4_sitl_default/rootfs/fs/microsd/etc/logging/logger_topics.txt`): +The list of logged topics can also be customized with a file on the SD card: `etc/logging/logger_topics.txt` (for SITL, it's `build/px4_sitl_default/rootfs/fs/microsd/etc/logging/logger_topics.txt`). + +Each topic to be logged is listed on a separate line, with the following format: ```plain ``` -The `` is optional, and if specified, defines the minimum interval in ms between two logged messages of this topic. -If not specified, the topic is logged at full rate. +Where: +- `` (optional). + Defines the minimum interval in ms between two logged messages of this topic. + If not specified or `0`, the topic is logged at full rate. +- `` (optional). + Defines the instance to log. + NOte that `` must be specified in order to set `instance` + + If not specified, all instances of the topic are logged. -The `` is optional, and if specified, defines the instance to log. -If not specified, all instances of the topic are logged. -To specify ``, `` must be specified. It can be set to 0 to log at full rate - -The topics in this file replace all of the default logged topics. +The topics in this file will be added on top of the already selected topics. +To just log the topics defined in this file, set [SDLOG_PROFILE=0](../advanced_config/parameter_reference.md#SDLOG_PROFILE). +If a topic is already included, it will update it's rate. Example : @@ -77,7 +83,7 @@ sensor_gyro 200 sensor_mag 200 1 ``` -This configuration will log sensor_accel 0 at full rate, sensor_accel 1 at 10Hz, all sensor_gyro instances at 5Hz and sensor_mag 1 at 5Hz. +This configuration will log sensor_accel 0 at full rate, sensor_accel 1 at 10Hz, all `sensor_gyro` instances at 5Hz and `sensor_mag` 1 at 5Hz. ## Scripts diff --git a/src/modules/logger/logged_topics.cpp b/src/modules/logger/logged_topics.cpp index 8bcf9a9608..d16804e79c 100644 --- a/src/modules/logger/logged_topics.cpp +++ b/src/modules/logger/logged_topics.cpp @@ -558,20 +558,6 @@ bool LoggedTopics::add_topic_multi(const char *name, uint16_t interval_ms, uint8 } bool LoggedTopics::initialize_logged_topics(SDLogProfileMask profile) -{ - int ntopics = add_topics_from_file(PX4_STORAGEDIR "/etc/logging/logger_topics.txt"); - - if (ntopics > 0) { - PX4_INFO("logging %d topics from logger_topics.txt", ntopics); - - } else { - initialize_configured_topics(profile); - } - - return _subscriptions.count > 0; -} - -void LoggedTopics::initialize_configured_topics(SDLogProfileMask profile) { // load appropriate topics for profile // the order matters: if several profiles add the same topic, the logging rate of the last one will be used @@ -622,4 +608,16 @@ void LoggedTopics::initialize_configured_topics(SDLogProfileMask profile) if (profile & SDLogProfileMask::HIGH_RATE_SENSORS) { add_high_rate_sensors_topics(); } + + int ntopics = add_topics_from_file(PX4_STORAGEDIR "/etc/logging/logger_topics.txt"); + + if (ntopics > 0) { + PX4_INFO("logging %d topics from logger_topics.txt", ntopics); + + } else if ((int32_t)profile == 0) { + PX4_WARN("No logging topics added. Using default set"); + add_default_topics(); + } + + return _subscriptions.count > 0; } diff --git a/src/modules/logger/logged_topics.h b/src/modules/logger/logged_topics.h index e7eb7676b6..ecb6d3e4bd 100644 --- a/src/modules/logger/logged_topics.h +++ b/src/modules/logger/logged_topics.h @@ -102,6 +102,9 @@ public: */ void initialize_mission_topics(MissionLogType mission_log_type); + /** + * Add topic subscriptions based on the profile configuration and additional topics from SD card + */ bool initialize_logged_topics(SDLogProfileMask profile); const RequestedSubscriptionArray &subscriptions() const { return _subscriptions; } @@ -160,11 +163,6 @@ private: */ void add_mission_topic(const char *name, uint16_t interval_ms = 0); - /** - * Add topic subscriptions based on the profile configuration - */ - void initialize_configured_topics(SDLogProfileMask profile); - void add_default_topics(); void add_estimator_replay_topics(); void add_thermal_calibration_topics(); diff --git a/src/modules/logger/logger.cpp b/src/modules/logger/logger.cpp index aaa24ca69b..0077e451af 100644 --- a/src/modules/logger/logger.cpp +++ b/src/modules/logger/logger.cpp @@ -507,11 +507,6 @@ bool Logger::initialize_topics() // get the logging profile SDLogProfileMask sdlog_profile = (SDLogProfileMask)_param_sdlog_profile.get(); - if ((int32_t)sdlog_profile == 0) { - PX4_WARN("No logging profile selected. Using default set"); - sdlog_profile = SDLogProfileMask::DEFAULT; - } - LoggedTopics logged_topics; logged_topics.set_rate_factor(_rate_factor);