93 return lifecycle_status;
129 if ((name != NULL) && (out_level != NULL))
192 const char *destination,
195 const char *extra_fields)
202 const char *ts_cstr = NULL;
203 const char *line_cstr = NULL;
237 if ((extra_fields != NULL) && (extra_fields[0] !=
'\0'))
251 s_backend->
write(level, source, (line_cstr != NULL) ? line_cstr :
"");
271 bool ok = (fields != NULL) && (key != NULL);
331 uint32_t value, uint8_t min_digits)
352 const char *out =
"";
356 const char *tmp = NULL;
370 const char *destination,
394 char num_storage[16];
396 const char *num_cstr = NULL;
sapi_status_t sapi_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
sapi_status_t sapi_log_register_backend(const sapi_log_backend_t *backend)
Registers the backend implementation used by sapi_log_init()/ sapi_log_write() (ADR-005 section 2....
void sapi_log_write_event(sapi_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/receive...
const char * sapi_log_level_to_string(sapi_log_level_t level)
Renders a sapi_log_level_t as a fixed, human-readable tag - "DEBUG"/"INFO"/"WARNING"/"ERROR" - used a...
sapi_log_level_t
Log message severity, passed to sapi_log_write().
const char * sapi_log_fields_c_str(sapi_log_fields_t *fields)
NUL-terminated view of the accumulated pairs.
sapi_log_level_t sapi_log_get_level(void)
Returns the current minimum severity (see sapi_log_set_level()). REQ-OAL-LOG-015.
void sapi_log_write_event_fields(sapi_log_level_t level, const char *site, uint32_t cycle, const char *source, const char *destination, const char *type, const char *info, sapi_log_fields_t *fields)
sapi_log_write_event() with a builder passed directly as the extra fields - no sapi_log_fields_c_str(...
void sapi_log_set_level(sapi_log_level_t min_level)
Sets the minimum severity that sapi_log_write() and sapi_log_write_event() forward to the backend - a...
sapi_status_t sapi_log_level_from_string(const char *name, sapi_log_level_t *out_level)
Parses one of the canonical level spellings ("DEBUG", "INFO", "WARNING", "ERROR" - exactly as sapi_lo...
sapi_status_t sapi_log_init(void)
Initializes the logging backend. Safe to call once at startup.
void sapi_log_fields_reset(sapi_log_fields_t *fields)
(Re)initialises a builder to empty. MUST be called before the first sapi_log_fields_add_*(); safe to ...
void sapi_log_write(sapi_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 dro...
#define SAPI_LOG_EVENT_LINE_MAX_LEN
Max length, in bytes and not counting the NUL terminator, of one sapi_log_write_event() line - fields...
sapi_log_fields_t * sapi_log_fields_add_str(sapi_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 no...
sapi_status_t
Common result/status codes.
@ SAPI_STATUS_INVALID_PARAM
sapi_status_t sapi_string_from_u64(sapi_string_t *dest, uint64_t value)
Bounded base-10 itoa equivalent for uint64_t. Replaces dest's content.
sapi_status_t sapi_string_init(sapi_string_t *str, char *storage, size_t capacity)
Binds a string to caller-owned storage. Initial length is 0 (empty string).
sapi_status_t sapi_string_c_str(sapi_string_t *str, const char **out_cstr)
Ensures a NUL terminator is present within capacity (without incrementing length) and returns a point...
sapi_status_t sapi_string_append_hex_u32(sapi_string_t *dest, uint32_t value, uint8_t min_digits)
Bounded append of a uint32_t formatted as lowercase hexadecimal (no "0x" prefix - the caller prepends...
sapi_status_t sapi_string_append_i64(sapi_string_t *dest, int64_t value)
Bounded base-10 append of an int64_t; a leading '-' is emitted for negative values....
size_t sapi_string_length(const sapi_string_t *str)
Returns a string's current length (not counting a NUL terminator).
sapi_status_t sapi_string_concat(sapi_string_t *dest, const char *src)
Bounded strcat equivalent. Never calls strlen(src) - scans for a NUL only up to dest's remaining capa...
sapi_status_t sapi_string_append_u32(sapi_string_t *dest, uint32_t value)
Bounded base-10 append of a uint32_t to dest's existing content (unlike sapi_string_from_u32(),...
sapi_status_t sapi_string_append_u64(sapi_string_t *dest, uint64_t value)
Bounded base-10 append of a uint64_t. See sapi_string_append_u32().
sapi_status_t sapi_string_append_i32(sapi_string_t *dest, int32_t value)
Bounded base-10 append of an int32_t; a leading '-' is emitted for negative values....
sapi_status_t sapi_string_from_u32(sapi_string_t *dest, uint32_t value)
Bounded base-10 itoa equivalent for uint32_t. Replaces dest's content.
sapi_status_t sapi_timer_now(sapi_timestamp_ms_t *out_now_ms)
Returns the current monotonic time base used by all timers.
uint64_t sapi_timestamp_ms_t
static const sapi_clocksync_backend_t * s_backend
Process-wide application setup-phase lock (ADR-026).
static bool sapi_log_fields_begin_pair(sapi_log_fields_t *fields, const char *key)
Appends the "[ ]key=" prefix of one pair (leading space only if the builder already holds something)....
static sapi_log_level_t s_min_level
Minimum severity forwarded to the backend (sapi_log_set_level()). SAPI_LOG_LEVEL_DEBUG = nothing filt...
static void sapi_log_append_event_field(sapi_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) - t...
static void sapi_log_append_event_field_u32(sapi_string_t *line, const char *key, uint32_t value)
Formats value in base 10 and appends it as "Key=value" via sapi_log_append_event_field()....
static const sapi_log_level_name_t s_level_names[]
The four canonical spellings, kept in sync with sapi_log_level_to_string().
OS Abstraction Layer - Logging/diagnostics service.
OS-backend adaptation surface for the Logging/diagnostics service (ADR-005, ADR-021).
Bounded, checked string manipulation (ADR-006). Replaces strcpy/strcat/sprintf/atoi/strtok-style unbo...
OS Abstraction Layer - Timer service.
Backend vtable: an integrator's implementation of the logging sink (ADR-005). Unlike every other OAL ...
sapi_status_t(*) init(void)
Backend implementation of sapi_log_init(). May be NULL.
void(*) write(sapi_log_level_t level, const char *tag, const char *message)
Backend implementation of sapi_log_write(). May be NULL.
Bounded builder for sapi_log_write_event()'s extra_fields (or info) argument: accumulates space-separ...
char storage[SAPI_LOG_EVENT_LINE_MAX_LEN]
One canonical level spelling <-> value pair for sapi_log_level_from_string().
Bounded string: buf.length is the string length, not counting a NUL.