Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_log.h
Go to the documentation of this file.
1
19#ifndef SAFEAPI_OS_LOG_H
20#define SAFEAPI_OS_LOG_H
21
24#include "safeapi/utils/string/sapi_string.h" /* sapi_log_fields_t backing store */
25
26#include <stdbool.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
40
49
58void sapi_log_write(sapi_log_level_t level, const char *tag, const char *message);
59
73
86
108
114
122#define SAPI_LOG_EVENT_LINE_MAX_LEN 256U
123
201 const char *site,
202 uint32_t cycle,
203 const char *source,
204 const char *destination,
205 const char *type,
206 const char *info,
207 const char *extra_fields);
208
231typedef struct sapi_log_fields_s
232{
236
245
261sapi_log_fields_t *sapi_log_fields_add_str(sapi_log_fields_t *fields, const char *key, const char *value);
262sapi_log_fields_t *sapi_log_fields_add_u32(sapi_log_fields_t *fields, const char *key, uint32_t value);
263sapi_log_fields_t *sapi_log_fields_add_i32(sapi_log_fields_t *fields, const char *key, int32_t value);
264sapi_log_fields_t *sapi_log_fields_add_u64(sapi_log_fields_t *fields, const char *key, uint64_t value);
265sapi_log_fields_t *sapi_log_fields_add_i64(sapi_log_fields_t *fields, const char *key, int64_t value);
266sapi_log_fields_t *sapi_log_fields_add_hex_u32(sapi_log_fields_t *fields, const char *key,
267 uint32_t value, uint8_t min_digits);
268sapi_log_fields_t *sapi_log_fields_add_bool(sapi_log_fields_t *fields, const char *key, bool value);
270
280const char *sapi_log_fields_c_str(sapi_log_fields_t *fields);
281
292 const char *site,
293 uint32_t cycle,
294 const char *source,
295 const char *destination,
296 const char *type,
297 const char *info,
298 sapi_log_fields_t *fields);
299
300/*
301 * The backend vtable (sapi_log_backend_t) and sapi_log_register_backend()
302 * live in safeapi_backend/log/sapi_log_backend.h, not here (ADR-021).
303 * This header is the consumer-facing surface only.
304 */
305
306#ifdef __cplusplus
307}
308#endif
309
310#endif /* SAFEAPI_OS_LOG_H */
311 /* LOG */
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...
Definition sapi_log.c:188
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...
Definition sapi_log.c:162
sapi_log_level_t
Log message severity, passed to sapi_log_write().
Definition sapi_log.h:34
const char * sapi_log_fields_c_str(sapi_log_fields_t *fields)
NUL-terminated view of the accumulated pairs.
Definition sapi_log.c:350
sapi_log_level_t sapi_log_get_level(void)
Returns the current minimum severity (see sapi_log_set_level()). REQ-OAL-LOG-015.
Definition sapi_log.c:157
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(...
Definition sapi_log.c:366
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...
Definition sapi_log.c:146
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...
Definition sapi_log.c:125
sapi_status_t sapi_log_init(void)
Initializes the logging backend. Safe to call once at startup.
Definition sapi_log.c:99
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 ...
Definition sapi_log.c:254
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...
Definition sapi_log.c:108
#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...
Definition sapi_log.h:122
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...
Definition sapi_log.c:285
@ SAPI_LOG_LEVEL_DEBUG
Definition sapi_log.h:35
@ SAPI_LOG_LEVEL_ERROR
Definition sapi_log.h:38
@ SAPI_LOG_LEVEL_INFO
Definition sapi_log.h:36
@ SAPI_LOG_LEVEL_WARNING
Definition sapi_log.h:37
sapi_status_t
Common result/status codes.
Definition sapi_status.h:27
Common status/error codes returned by every Safe API Framework function. Shared across all OS Abstrac...
Bounded, checked string manipulation (ADR-006). Replaces strcpy/strcat/sprintf/atoi/strtok-style unbo...
Common fixed-width types and the caller-owned-storage handle pattern used by every OAL service (see A...
Bounded builder for sapi_log_write_event()'s extra_fields (or info) argument: accumulates space-separ...
Definition sapi_log.h:232
sapi_string_t str
Definition sapi_log.h:233
char storage[SAPI_LOG_EVENT_LINE_MAX_LEN]
Definition sapi_log.h:234
Bounded string: buf.length is the string length, not counting a NUL.
Definition sapi_string.h:39