BSL v0.0.0
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 dependency graph for LoggingStderr.c:

Go to the source code of this file.

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()   (INIT(API_2(BSL_LogEvent_event_init)), CLEAR(API_2(BSL_LogEvent_event_deinit)))
 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)
 
uint8_t * BSL_Log_DumpAsHexString (uint8_t *dstbuf, size_t dstlen, const uint8_t *srcbuf, size_t srclen)
 NOLINTEND.
 
static void write_log (const BSL_LogEvent_event_t *event)
 NOLINTBEGIN.
 
static void * work_sink (void *arg)
 NOLINTEND.
 
void BSL_openlog (void)
 Opens the event log.
 
void BSL_closelog (void)
 Closes the event log.
 
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 BSL_LogEvent_queue_t event_queue
 NOLINTBEGIN.
 
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.

Definition in file LoggingStderr.c.

Macro Definition Documentation

◆ BSL_LOG_QUEUE_SIZE

#define BSL_LOG_QUEUE_SIZE   100

Number of events to buffer to I/O thread.

Definition at line 40 of file LoggingStderr.c.

◆ M_OPL_BSL_LogEvent_event_t

#define M_OPL_BSL_LogEvent_event_t ( )    (INIT(API_2(BSL_LogEvent_event_init)), CLEAR(API_2(BSL_LogEvent_event_deinit)))

OPLIST for BSL_LogEvent_event_t.

Definition at line 86 of file LoggingStderr.c.

Function Documentation

◆ BSL_closelog()

void BSL_closelog ( void  )

Closes the event log.

This is a mimic to POSIX closelog()

See also
BSL_openlog

Definition at line 195 of file LoggingStderr.c.

References event_queue, BSL_LogEvent_event_t::message, BSL_LogEvent_event_t::severity, thr_sink, thr_valid, and write_log().

◆ BSL_Log_DumpAsHexString()

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

NOLINTEND.

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

Definition at line 101 of file LoggingStderr.c.

◆ 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.

Definition at line 220 of file LoggingStderr.c.

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

◆ BSL_LogEvent_event_deinit()

static void BSL_LogEvent_event_deinit ( BSL_LogEvent_event_t obj)
static

Definition at line 79 of file LoggingStderr.c.

◆ BSL_LogEvent_event_init()

static void BSL_LogEvent_event_init ( BSL_LogEvent_event_t obj)
static

Definition at line 70 of file LoggingStderr.c.

◆ 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()

Definition at line 175 of file LoggingStderr.c.

References BSL_LOG_QUEUE_SIZE, event_queue, BSL_LogEvent_event_t::message, BSL_LogEvent_event_t::severity, thr_sink, thr_valid, work_sink(), and write_log().

◆ work_sink()

static void * work_sink ( void *  arg)
static

NOLINTEND.

Definition at line 157 of file LoggingStderr.c.

References event_queue, BSL_LogEvent_event_t::message, and write_log().

Referenced by BSL_openlog().

◆ write_log()

static void write_log ( const BSL_LogEvent_event_t event)
static

Variable Documentation

◆ event_queue

BSL_LogEvent_queue_t event_queue
static

NOLINTBEGIN.

Shared safe queue

Definition at line 94 of file LoggingStderr.c.

Referenced by BSL_closelog(), BSL_LogEvent(), BSL_openlog(), and work_sink().

◆ sev_names

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

Definition at line 43 of file LoggingStderr.c.

◆ thr_sink

pthread_t thr_sink
static

Sink thread ID.

Definition at line 96 of file LoggingStderr.c.

Referenced by BSL_closelog(), and BSL_openlog().

◆ thr_valid

atomic_bool thr_valid = ATOMIC_VAR_INIT(false)
static

True if thr_sink is valid.

Definition at line 98 of file LoggingStderr.c.

Referenced by BSL_closelog(), BSL_LogEvent(), and BSL_openlog().