DTNMA Reference Tools v2.1.0 - 13.gc5c0bac
Delay-Tolerant Networking Management Architecture (DTNMA) Tool Suite
Loading...
Searching...
No Matches
logging_stderr.c File Reference
#include "cace/config.h"
#include "logging.h"
#include "defs.h"
#include <m-buffer.h>
#include <m-string.h>
#include <m-atomic.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <strings.h>
#include <sys/time.h>
#include <time.h>
+ Include dependency graph for logging_stderr.c:

Data Structures

struct  cace_log_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_cace_log_event_t()
 OPLIST for cace_log_event_t.
 

Functions

void cace_log_event_init (cace_log_event_t *obj)
 
static void cace_log_event_init_set (cace_log_event_t *obj, const cace_log_event_t *src)
 
static void cace_log_event_init_move (cace_log_event_t *obj, cace_log_event_t *src)
 
static void cace_log_event_set (cace_log_event_t *obj, const cace_log_event_t *src)
 
void cace_log_event_deinit (cace_log_event_t *obj)
 
static void write_log (const cace_log_event_t *event)
 
static void * work_sink (void *arg)
 
void cace_openlog (void)
 Opens the event log.
 
void cace_closelog (void)
 Closes the event log.
 
int cace_log_get_severity (int *severity, const char *name)
 Interpret a text name as a severity level.
 
void cace_log_set_least_severity (int severity)
 Set the least severity enabled for logging.
 
bool cace_log_is_enabled_for (int severity)
 Determine if a particular severity is being logged.
 
void cace_log (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 cace_log_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.
 
static atomic_bool did_crit = ATOMIC_VAR_INIT(false)
 Log internal error once.
 

Macro Definition Documentation

◆ BSL_LOG_QUEUE_SIZE

#define BSL_LOG_QUEUE_SIZE   100

Number of events to buffer to I/O thread.

◆ M_OPL_cace_log_event_t

#define M_OPL_cace_log_event_t ( )
Value:
(INIT(API_2(cace_log_event_init)), INIT_SET(API_6(cace_log_event_init_set)), \
INIT_MOVE(API_6(cace_log_event_init_move)), SET(API_6(cace_log_event_set)), CLEAR(API_2(cace_log_event_deinit)))
static void cace_log_event_set(cace_log_event_t *obj, const cace_log_event_t *src)
Definition logging_stderr.c:87
void cace_log_event_init(cace_log_event_t *obj)
Definition logging_stderr.c:60
static void cace_log_event_init_move(cace_log_event_t *obj, cace_log_event_t *src)
Definition logging_stderr.c:78
static void cace_log_event_init_set(cace_log_event_t *obj, const cace_log_event_t *src)
Definition logging_stderr.c:69
void cace_log_event_deinit(cace_log_event_t *obj)
Definition logging_stderr.c:96

OPLIST for cace_log_event_t.

Function Documentation

◆ cace_closelog()

void cace_closelog ( void  )

Closes the event log.

This is a mimic to POSIX closelog()

See also
cace_openlog

References cace_log_event_deinit(), cace_log_event_init(), event_queue, cace_log_event_t::message, cace_log_event_t::severity, thr_sink, thr_valid, and write_log().

Referenced by main(), and suiteTearDown().

◆ cace_log()

void cace_log ( 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 cace_log_event_deinit(), cace_log_event_init(), cace_log_is_enabled_for(), cace_log_event_t::context, did_crit, event_queue, cace_log_event_t::message, cace_log_event_t::severity, thr_valid, va_end(), va_start(), and write_log().

◆ cace_log_event_deinit()

void cace_log_event_deinit ( cace_log_event_t obj)

◆ cace_log_event_init()

◆ cace_log_event_init_move()

◆ cace_log_event_init_set()

◆ cace_log_event_set()

◆ cace_log_get_severity()

int cace_log_get_severity ( 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, and sev_names.

Referenced by main(), and mgr_parse_args().

◆ cace_log_is_enabled_for()

◆ cace_log_set_least_severity()

void cace_log_set_least_severity ( 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
cace_log_is_enabled_for

References least_severity.

Referenced by LLVMFuzzerInitialize(), and main().

◆ cace_openlog()

void cace_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 cace_closelog()

This is a mimic to POSIX openlog()

References BSL_LOG_QUEUE_SIZE, cace_log_event_deinit(), cace_log_event_init(), event_queue, cace_log_event_t::message, cace_log_event_t::severity, thr_sink, thr_valid, work_sink(), and write_log().

Referenced by LLVMFuzzerInitialize(), main(), and suiteSetUp().

◆ work_sink()

static void * work_sink ( void *  arg)
static

◆ write_log()

static void write_log ( const cace_log_event_t event)
static

References CHKVOID, and sev_names.

Referenced by cace_closelog(), cace_log(), cace_openlog(), and work_sink().

Variable Documentation

◆ did_crit

atomic_bool did_crit = ATOMIC_VAR_INIT(false)
static

Log internal error once.

Referenced by cace_log().

◆ event_queue

cace_log_queue_t event_queue
static

Shared safe queue.

Referenced by cace_closelog(), cace_log(), cace_openlog(), and work_sink().

◆ least_severity

atomic_int least_severity = LOG_DEBUG
static

Shared least severity.

Referenced by cace_log_is_enabled_for(), and cace_log_set_least_severity().

◆ sev_names

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

Referenced by cace_log_get_severity(), and write_log().

◆ thr_sink

pthread_t thr_sink
static

Sink thread ID.

Referenced by cace_closelog(), and cace_openlog().

◆ thr_valid

atomic_bool thr_valid = ATOMIC_VAR_INIT(false)
static

True if thr_sink is valid.

Referenced by cace_closelog(), cace_log(), and cace_openlog().