BSL v0.0.0 - 0.geda3e66
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
LoggingStderr.c File Reference

Implementation of event logging using stderr output stream. More...

#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <strings.h>
#include <sys/time.h>
#include <time.h>
#include <BPSecLib_Private.h>
#include <BSLConfig.h>
#include <m-buffer.h>
#include <m-string.h>
#include <m-atomic.h>
+ Include dependency graph for LoggingStderr.c:

Data Structures

struct  BSL_LogEvent_event_t
 A single event for the log. More...
 

Macros

#define BSL_LOG_QUEUE_SIZE   100
 Number of events to buffer to I/O thread.
 
#define M_OPL_BSL_LogEvent_event_t()
 OPLIST for BSL_LogEvent_event_t.
 

Functions

static void BSL_LogEvent_event_init (BSL_LogEvent_event_t *obj)
 
static void BSL_LogEvent_event_deinit (BSL_LogEvent_event_t *obj)
 
static void BSL_LogEvent_event_init_set (BSL_LogEvent_event_t *obj, const BSL_LogEvent_event_t *src)
 
static void BSL_LogEvent_event_init_move (BSL_LogEvent_event_t *obj, BSL_LogEvent_event_t *src)
 
static void BSL_LogEvent_event_set (BSL_LogEvent_event_t *obj, const BSL_LogEvent_event_t *src)
 
uint8_t * BSL_Log_DumpAsHexString (uint8_t *dstbuf, size_t dstlen, const uint8_t *srcbuf, size_t srclen)
 Helper function to print the ASCII encoding of a given byte stream to a given target buffer.
 
static void write_log (const BSL_LogEvent_event_t *event)
 
static void * work_sink (void *arg)
 
void BSL_openlog (void)
 Opens the event log.
 
void BSL_closelog (void)
 Closes the event log.
 
int BSL_LogGetSeverity (int *severity, const char *name)
 Interpret a text name as a severity level.
 
void BSL_LogSetLeastSeverity (int severity)
 Set the least severity enabled for logging.
 
bool BSL_LogIsEnabledFor (int severity)
 Determine if a particular severity is being logged.
 
void BSL_LogEvent (int severity, const char *filename, int lineno, const char *funcname, const char *format,...)
 Log an event.
 

Variables

static const char * sev_names []
 
static atomic_int least_severity = LOG_DEBUG
 Shared least severity.
 
static BSL_LogEvent_queue_t event_queue
 Shared safe queue.
 
static pthread_t thr_sink
 Sink thread ID.
 
static atomic_bool thr_valid = ATOMIC_VAR_INIT(false)
 True if thr_sink is valid.
 

Detailed Description

Implementation of event logging using stderr output stream.

Macro Definition Documentation

◆ M_OPL_BSL_LogEvent_event_t

#define M_OPL_BSL_LogEvent_event_t ( )
Value:
(INIT(API_2(BSL_LogEvent_event_init)), INIT_SET(API_6(BSL_LogEvent_event_init_set)), \
INIT_MOVE(API_6(BSL_LogEvent_event_init_move)), SET(API_6(BSL_LogEvent_event_set)), \
CLEAR(API_2(BSL_LogEvent_event_deinit)))

OPLIST for BSL_LogEvent_event_t.

Function Documentation

◆ BSL_closelog()

void BSL_closelog ( void  )

Closes the event log.

This is a mimic to POSIX closelog()

See also
BSL_openlog

References event_queue, BSL_LogEvent_event_t::message, BSL_LogEvent_event_t::severity, thr_sink, and thr_valid.

◆ BSL_Log_DumpAsHexString()

uint8_t * BSL_Log_DumpAsHexString ( uint8_t *  dstbuf,
size_t  dstlen,
const uint8_t *  srcbuf,
size_t  srclen 
)

Helper function to print the ASCII encoding of a given byte stream to a given target buffer.

Todo:
  • Can be moved to backend.
Parameters
dstbufPointer to a buffer where the C string should go.
dstlenThe length in bytes of dstbuf
srcbufPointer to the buffer containing the byte stream to be printed.
srclenThe length in bytes of srcbuf.
Returns
The number of bytes written to dstbuf. It will not exceed dstlen.

Referenced by BSL_AbsSecBlock_Print(), test_RFC9173_AppendixA_Example2_BCB_Acceptor(), and test_RFC9173_AppendixA_Example2_BCB_Source().

◆ BSL_LogEvent()

void BSL_LogEvent ( int  severity,
const char *  filename,
int  lineno,
const char *  funcname,
const char *  format,
  ... 
)

Log an event.

Parameters
severityThe severity from a subset of the POSIX syslog values.
[in]filenameThe originating file name, which may include directory parts.
[in]linenoThe originating file line number.
[in]funcnameThe originating function name.
[in]formatThe log message format string.
...Values for the format string.

References BSL_LogIsEnabledFor(), BSL_LogEvent_event_t::context, event_queue, BSL_LogEvent_event_t::message, BSL_LogEvent_event_t::severity, and thr_valid.

◆ BSL_LogGetSeverity()

int BSL_LogGetSeverity ( int *  severity,
const char *  name 
)

Interpret a text name as a severity level.

Parameters
[out]severityThe associated severity level.
[in]nameThe text name, which is case insensitive.
Returns
Zero if successful.

References CHKERR1.

◆ BSL_LogIsEnabledFor()

bool BSL_LogIsEnabledFor ( int  severity)

Determine if a particular severity is being logged.

This function is multi-thread safe.

Parameters
severityThe severity from a subset of the POSIX syslog values.
Returns
True if the severity level will be logged.
See also
BSL_log_set_least_severity()

References least_severity.

Referenced by BSL_LogEvent().

◆ BSL_LogSetLeastSeverity()

void BSL_LogSetLeastSeverity ( int  severity)

Set the least severity enabled for logging.

Other events will be dropped by the logging facility. This function is multi-thread safe.

Parameters
severityThe severity from a subset of the POSIX syslog values.
See also
BSL_log_is_enabled_for()

References least_severity.

◆ BSL_openlog()

void BSL_openlog ( void  )

Opens the event log.

Note
This should be called once per process, not thread or library instance. At the end of the process there should be a call to BSL_closelog()

This is a mimic to POSIX openlog()

References BSL_LOG_QUEUE_SIZE, event_queue, BSL_LogEvent_event_t::message, BSL_LogEvent_event_t::severity, thr_sink, and thr_valid.

Variable Documentation

◆ sev_names

const char* sev_names[]
static
Initial value:
= {
NULL,
NULL,
"CRIT",
"ERROR",
"WARNING",
NULL,
"INFO",
"DEBUG",
}