Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
rte_log.c File Reference

Logging service: dispatches to the OSAdapter registered via rte_osadapter_log_register() (ADR-005). No OSAdapter registered is not an error for this service - see rte_log.h. More...

Include dependency graph for rte_log.c:

Go to the source code of this file.

Data Structures

struct  rte_log_level_name_t
 One canonical level spelling <-> value pair for rte_log_level_from_string(). More...

Functions

static void rte_log_append_event_field (rte_string_t *line, const char *key, const char *value)
 Appends " Key=Value" to *line (a leading space, then key, "=", then value or "" if value is NULL) - the Key=Value pair convention rte_log_write_event() uses for every field. Best-effort: a RTE_STATUS_RESOURCE_EXHAUSTED from any concat is silently accepted (line is left truncated at whatever fit) - REQ-OAL-LOG-001, this must never fail the caller's control flow, so there is nothing to report here.
static void rte_log_append_event_field_u32 (rte_string_t *line, const char *key, uint32_t value)
 Formats value in base 10 and appends it as "Key=value" via rte_log_append_event_field(). Uses a small local rte_string_t/buffer, independent of *line's own storage.
rte_status_t rte_osadapter_log_register (const rte_osadapter_log_t *osadapter)
 Registers the OSAdapter log implementation.
rte_status_t rte_log_init (void)
 Initializes the logging OSAdapter. Safe to call once at startup.
void rte_log_write (rte_log_level_t level, const char *tag, const char *message)
 Emits one log message. Non-blocking; never fails the caller's control flow even if the message is dropped.
rte_status_t rte_log_level_from_string (const char *name, rte_log_level_t *out_level)
 Parses one of the canonical level spellings ("DEBUG", "INFO", "WARNING", "ERROR" - exactly as rte_log_level_to_string() renders them, case-sensitive) into a rte_log_level_t.
void rte_log_set_level (rte_log_level_t min_level)
 Sets the minimum severity that rte_log_write() and rte_log_write_event() forward to the OSAdapter - a call whose level is below min_level is dropped before dispatch (and before any formatting work). Default is RTE_LOG_LEVEL_DEBUG: nothing is filtered until this is called.
rte_log_level_t rte_log_get_level (void)
 Returns the current minimum severity (see rte_log_set_level()). REQ-OAL-LOG-015.
const char * rte_log_level_to_string (rte_log_level_t level)
 Renders a rte_log_level_t as a fixed, human-readable tag - "DEBUG"/"INFO"/"WARNING"/"ERROR" - used as the LEVEL field of rte_log_write_event()'s structured line and available to any OSAdapter/integrator wanting the same canonical spelling.
void rte_log_write_event (rte_log_level_t level, const char *site, uint32_t cycle, const char *source, const char *destination, const char *type, const char *info, const char *extra_fields)
 Emits one structured inter-channel event/message-trail log line - for a message actually sent/received/decided between channels or nodes (e.g. an AB_SAMPLE frame, an M136 report, a checkpoint REQUEST/REPLY, a cross-compare AGREE/DISAGREE) - distinct from rte_log_write()'s free-text diagnostic logging, which remains the right call for an event with no natural cycle/source/destination (e.g. an NVM write failure).
void rte_log_fields_reset (rte_log_fields_t *fields)
 (Re)initialises a builder to empty. MUST be called before the first rte_log_fields_add_*(); safe to call again to reuse the same builder for another line.
static bool rte_log_fields_begin_pair (rte_log_fields_t *fields, const char *key)
 Appends the "[ ]key=" prefix of one pair (leading space only if the builder already holds something). Best-effort; a truncated concat is silently accepted (REQ-OAL-LOG-001).
rte_log_fields_t * rte_log_fields_add_str (rte_log_fields_t *fields, const char *key, const char *value)
 Appends one key=value pair (preceded by a single separating space only when the builder is already non-empty).
rte_log_fields_t * rte_log_fields_add_u32 (rte_log_fields_t *fields, const char *key, uint32_t value)
rte_log_fields_t * rte_log_fields_add_i32 (rte_log_fields_t *fields, const char *key, int32_t value)
rte_log_fields_t * rte_log_fields_add_u64 (rte_log_fields_t *fields, const char *key, uint64_t value)
rte_log_fields_t * rte_log_fields_add_i64 (rte_log_fields_t *fields, const char *key, int64_t value)
rte_log_fields_t * rte_log_fields_add_hex_u32 (rte_log_fields_t *fields, const char *key, uint32_t value, uint8_t min_digits)
rte_log_fields_t * rte_log_fields_add_bool (rte_log_fields_t *fields, const char *key, bool value)
const char * rte_log_fields_c_str (rte_log_fields_t *fields)
 NUL-terminated view of the accumulated pairs.
void rte_log_write_event_fields (rte_log_level_t level, const char *site, uint32_t cycle, const char *source, const char *destination, const char *type, const char *info, rte_log_fields_t *fields)
 rte_log_write_event() with a builder passed directly as the extra fields - no rte_log_fields_c_str() at the call site.

Variables

static const rte_osadapter_log_t * s_osadapter = NULL
 Currently registered OSAdapter, or NULL if none (ADR-005).
static rte_log_level_t s_min_level = RTE_LOG_LEVEL_DEBUG
 Minimum severity forwarded to the OSAdapter (rte_log_set_level()). RTE_LOG_LEVEL_DEBUG = nothing filtered - the historical behaviour before this threshold existed.
static const rte_log_level_name_t s_level_names []
 The four canonical spellings, kept in sync with rte_log_level_to_string().

Detailed Description

Logging service: dispatches to the OSAdapter registered via rte_osadapter_log_register() (ADR-005). No OSAdapter registered is not an error for this service - see rte_log.h.

rte_log_write_event()'s structured-line formatting (added alongside this file's own module) is what introduces this module's only two new dependencies, rte::string (bounded formatting - ADR-006) and rte::timer (TIMESTAMP field - rte_timer_now()); rte_log_write() itself and the OSAdapter dispatch below are unchanged and still have neither dependency.

Definition in file rte_log.c.

Function Documentation

◆ rte_log_append_event_field()

void rte_log_append_event_field ( rte_string_t * line,
const char * key,
const char * value )
static

Appends " Key=Value" to *line (a leading space, then key, "=", then value or "" if value is NULL) - the Key=Value pair convention rte_log_write_event() uses for every field. Best-effort: a RTE_STATUS_RESOURCE_EXHAUSTED from any concat is silently accepted (line is left truncated at whatever fit) - REQ-OAL-LOG-001, this must never fail the caller's control flow, so there is nothing to report here.

Global variables declarations Local function declarations

Parameters
lineLine being built. Must not be NULL.
keyField key/label (e.g. "Cycle"). Must not be NULL.
valueField value to append; NULL is treated as an empty value.

Definition at line 384 of file rte_log.c.

◆ rte_log_append_event_field_u32()

void rte_log_append_event_field_u32 ( rte_string_t * line,
const char * key,
uint32_t value )
static

Formats value in base 10 and appends it as "Key=value" via rte_log_append_event_field(). Uses a small local rte_string_t/buffer, independent of *line's own storage.

Parameters
lineLine being built. Must not be NULL.
keyField key/label. Must not be NULL.
valueValue to format.

Definition at line 392 of file rte_log.c.

◆ rte_osadapter_log_register()

rte_status_t rte_osadapter_log_register ( const rte_osadapter_log_t * adapter)

Registers the OSAdapter log implementation.

Global functions

Parameters
adapterPointer to log operations vtable.
Returns
RTE_STATUS_OK on success, RTE_STATUS_INVALID_PARAM if adapter is NULL, or RTE_STATUS_INVALID_STATE if the setup phase is already locked (REQ-LIFECYCLE-001, ADR-026; the previous registration, if any, is kept).

REQ-OAL-LOG-012: Follows the OSAdapter-registration contract (ADR-005 section 2.1): a NULL adapter is rejected with RTE_STATUS_INVALID_PARAM; re-registering replaces the previous OSAdapter. Exception for this service only (ADR-005 section 2.5): no OSAdapter registered is not an error; rte_log_write() then silently does nothing.

Definition at line 80 of file rte_log.c.

◆ rte_log_fields_begin_pair()

bool rte_log_fields_begin_pair ( rte_log_fields_t * fields,
const char * key )
static

Appends the "[ ]key=" prefix of one pair (leading space only if the builder already holds something). Best-effort; a truncated concat is silently accepted (REQ-OAL-LOG-001).

Returns
true if fields and key are both non-NULL (i.e. the caller should append the value), false otherwise.

Definition at line 269 of file rte_log.c.

Variable Documentation

◆ s_osadapter

const rte_osadapter_log_t* s_osadapter = NULL
static

Currently registered OSAdapter, or NULL if none (ADR-005).

Local variables declarations

Definition at line 36 of file rte_log.c.

◆ s_min_level

rte_log_level_t s_min_level = RTE_LOG_LEVEL_DEBUG
static

Minimum severity forwarded to the OSAdapter (rte_log_set_level()). RTE_LOG_LEVEL_DEBUG = nothing filtered - the historical behaviour before this threshold existed.

Definition at line 41 of file rte_log.c.

◆ s_level_names

const rte_log_level_name_t s_level_names[]
static
Initial value:
= {
{ "DEBUG", RTE_LOG_LEVEL_DEBUG },
{ "INFO", RTE_LOG_LEVEL_INFO },
{ "WARNING", RTE_LOG_LEVEL_WARNING },
{ "ERROR", RTE_LOG_LEVEL_ERROR }
}
@ RTE_LOG_LEVEL_DEBUG
Definition rte_log.h:35
@ RTE_LOG_LEVEL_INFO
Definition rte_log.h:36
@ RTE_LOG_LEVEL_WARNING
Definition rte_log.h:37
@ RTE_LOG_LEVEL_ERROR
Definition rte_log.h:38

The four canonical spellings, kept in sync with rte_log_level_to_string().

Definition at line 45 of file rte_log.c.