SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
satnogs::comms::logger Class Reference

A centralized, thread-safe logging utility for the SatNOGS-COMMS MCU software. More...

#include <logger.hpp>

Classes

class  ring_buf_msg

Public Types

enum class  target { RTT = 0 , UART = 1 , RING_BUFFER = 2 , STORAGE = 3 }
 Enumeration for targets to send logs to. More...

Public Member Functions

 logger (logger const &)=delete
 Disabled copy constructor to enforce singleton.
void operator= (logger const &)=delete
 Disabled assignment operator to enforce singleton.
void boot ()
 Logs system initialization details to multiple targets (RTT, UART, and RING_BUFFER).
void log (std::initializer_list< target > list, const lib::exception &e)
 Logs a satnogs::comms::lib::exception to a specified set of targets.
void log (std::initializer_list< target > list, const std::exception &e)
 Logs a std::exception to specified targets.
void log (std::initializer_list< target > list, const etl::exception &e)
 Logs an etl::exception to specified targets.
void log (std::initializer_list< target > list, const char *msg)
 Logs a C-string message to specified targets.
void log (const lib::exception &e)
 Logs a SatNOGS-COMMS exception to all default targets (RTT, UART, RING_BUFFER, EMMC). Additionally, the exceptions are saved to BACKUP_SRAM for retention based on the severity level defined by CONFIG_BACKUP_SRAM_EXCEPTION_LOG_LEVEL.
void log (const std::exception &e)
 Logs a std::exception to all default targets (RTT, UART, RING_BUFFER, EMMC). Additionally, the std::exceptions are saved to BACKUP_SRAM for retention.
void log (const etl::exception &e)
 Logs an etl::exception to all default targets (RTT, UART, RING_BUFFER, EMMC). Additionally, the exceptions are saved to BACKUP_SRAM for retention based on the severity level defined by CONFIG_BACKUP_SRAM_EXCEPTION_LOG_LEVEL.
void log (const char *msg)
 Logs a C-string message to all default targets (RTT, UART, RING_BUFFER, EMMC).
void log (const etl::istring &msg)
 Logs an ETL istring message to all default targets.
etl::string< CONFIG_LOG_MAX_MSG_LEN > get_latest_exception () const
 Retrieves the latest exception message stored in BACKUP_SRAM.
void delete_storage_logs (struct tm &start, struct tm &end)
void get_ring_buffer_log (ring_buf_msg &data, size_t index)
size_t get_ring_buffer_size ()

Static Public Member Functions

static loggerget_instance ()
 Singleton access to the logger subsystem.

Static Public Attributes

static constexpr const char * mcu_log_dir = "/SD" CONFIG_STORAGE_LOG_MCU_PATH

Detailed Description

A centralized, thread-safe logging utility for the SatNOGS-COMMS MCU software.

The logger class is designed to facilitate a consistent approach to logging within the SatNOGS-COMMS system. It supports multiple log targets:

  • RTT (Real-Time Transfer)
  • UART output
  • Ring buffer storage for historical retrieval
  • storage/eMMC for persistent storage

The logger class is a singleton, ensuring that all system components share the same logging interface. It can log messages and exceptions, including those derived from the satnogs::comms::lib::exception class and standard exceptions.

Usage involves obtaining the singleton instance via logger::get_instance() and calling the appropriate log() method for the data type at hand.

The logs that are stored in the eMMC storage are stored in the /SD/CONFIG_STORAGE_LOG_MCU_PATH directory, which is defined by the KConfig option CONFIG_STORAGE_LOG_MCU_PATH. The logs are stored in a file named YYYY-MM-DD.log, where DD is the day, MM is the month, and YYYY is the year. In case no date infomation is available, the file is named (e.g. no RTC or no GNSS) the file naming scheme that is used is the boot-<boot_counter>-<day>.log. The day starts from 0 and increments every 24 hours based on the uptime.

Definition at line 67 of file logger.hpp.

Member Enumeration Documentation

◆ target

enum class satnogs::comms::logger::target
strong

Enumeration for targets to send logs to.

Enumerator
RTT 

Real-Time Transfer logging (Segger RTT).

UART 

UART logging output.

RING_BUFFER 

In-memory ring buffer for storing recent log messages.

STORAGE 

eMMC logging for persistent storage

Definition at line 75 of file logger.hpp.

Constructor & Destructor Documentation

◆ logger()

satnogs::comms::logger::logger ( logger const & )
delete

Disabled copy constructor to enforce singleton.

Member Function Documentation

◆ boot()

void satnogs::comms::logger::boot ( )

Logs system initialization details to multiple targets (RTT, UART, and RING_BUFFER).

Gathers firmware, library, and hardware version information, constructs a descriptive message, and logs it. This method is typically called once at system startup.

Definition at line 93 of file logger.cpp.

◆ delete_storage_logs()

void satnogs::comms::logger::delete_storage_logs ( struct tm & start,
struct tm & end )

Definition at line 682 of file logger.cpp.

◆ get_instance()

logger & satnogs::comms::logger::get_instance ( )
inlinestatic

Singleton access to the logger subsystem.

Returns
logger&

Definition at line 102 of file logger.hpp.

◆ get_latest_exception()

etl::string< CONFIG_LOG_MAX_MSG_LEN > satnogs::comms::logger::get_latest_exception ( ) const

Retrieves the latest exception message stored in BACKUP_SRAM.

Returns
A C-style string containing the latest exception message or a default message if no exception has been logged.

Definition at line 791 of file logger.cpp.

◆ get_ring_buffer_log()

void satnogs::comms::logger::get_ring_buffer_log ( ring_buf_msg & data,
size_t index )

Definition at line 780 of file logger.cpp.

◆ get_ring_buffer_size()

size_t satnogs::comms::logger::get_ring_buffer_size ( )

Definition at line 774 of file logger.cpp.

◆ log() [1/9]

void satnogs::comms::logger::log ( const char * msg)

Logs a C-string message to all default targets (RTT, UART, RING_BUFFER, EMMC).

Parameters
msgThe null-terminated string to be logged.

Definition at line 157 of file logger.cpp.

◆ log() [2/9]

void satnogs::comms::logger::log ( const etl::exception & e)

Logs an etl::exception to all default targets (RTT, UART, RING_BUFFER, EMMC). Additionally, the exceptions are saved to BACKUP_SRAM for retention based on the severity level defined by CONFIG_BACKUP_SRAM_EXCEPTION_LOG_LEVEL.

Parameters
eThe etl::exception object containing error details.

Definition at line 132 of file logger.cpp.

◆ log() [3/9]

void satnogs::comms::logger::log ( const etl::istring & msg)

Logs an ETL istring message to all default targets.

Parameters
msgThe etl::istring object whose contents will be logged.

Definition at line 168 of file logger.cpp.

◆ log() [4/9]

void satnogs::comms::logger::log ( const lib::exception & e)

Logs a SatNOGS-COMMS exception to all default targets (RTT, UART, RING_BUFFER, EMMC). Additionally, the exceptions are saved to BACKUP_SRAM for retention based on the severity level defined by CONFIG_BACKUP_SRAM_EXCEPTION_LOG_LEVEL.

Parameters
eThe lib::exception object containing error details.

Definition at line 117 of file logger.cpp.

◆ log() [5/9]

void satnogs::comms::logger::log ( const std::exception & e)

Logs a std::exception to all default targets (RTT, UART, RING_BUFFER, EMMC). Additionally, the std::exceptions are saved to BACKUP_SRAM for retention.

Parameters
eThe standard exception object containing error details.

Definition at line 145 of file logger.cpp.

◆ log() [6/9]

void satnogs::comms::logger::log ( std::initializer_list< target > list,
const char * msg )

Logs a C-string message to specified targets.

This method provides control over which outputs receive the log message.

Parameters
listAn initializer list specifying the desired logging targets.
msgThe null-terminated string to be logged.

Definition at line 235 of file logger.cpp.

◆ log() [7/9]

void satnogs::comms::logger::log ( std::initializer_list< target > list,
const etl::exception & e )

Logs an etl::exception to specified targets.

This method provides control over which outputs receive the log message.

Parameters
listAn initializer list specifying the desired logging targets.
eThe standard exception object containing error details.

Definition at line 218 of file logger.cpp.

◆ log() [8/9]

void satnogs::comms::logger::log ( std::initializer_list< target > list,
const lib::exception & e )

Logs a satnogs::comms::lib::exception to a specified set of targets.

This method provides control over which outputs receive the log message.

Parameters
listAn initializer list specifying the desired logging targets.
eThe satnogs::comms::lib::exception object to be logged.

Definition at line 184 of file logger.cpp.

◆ log() [9/9]

void satnogs::comms::logger::log ( std::initializer_list< target > list,
const std::exception & e )

Logs a std::exception to specified targets.

This method provides control over which outputs receive the log message.

Parameters
listAn initializer list specifying the desired logging targets.
eThe standard exception object containing error details.

Definition at line 201 of file logger.cpp.

◆ operator=()

void satnogs::comms::logger::operator= ( logger const & )
delete

Disabled assignment operator to enforce singleton.

Member Data Documentation

◆ mcu_log_dir

const char* satnogs::comms::logger::mcu_log_dir = "/SD" CONFIG_STORAGE_LOG_MCU_PATH
staticconstexpr

Definition at line 70 of file logger.hpp.


The documentation for this class was generated from the following files: