EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
Macros | Functions
log.c File Reference
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <inttypes.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include "log.h"
Include dependency graph for log.c:

Macros

#define _POSIX_C_SOURCE   200112L
 
#define PRINT_COLOR(stream, time, color, name, err, file, line)
 
#define PRINT_NO_COLOR(stream, time, color, name, err, file, line)    fprintf(stream, "%s %-5s%s %s:%d: ", time, name, err, file, line)
 

Functions

void log_set_lock (log_lock_fn fn)
 
void log_set_level (uint8_t level)
 
void log_set_quiet (bool enable)
 
void log_set_meta (bool enable)
 
void log_set_color (bool enable)
 
int log_open_file (char *path)
 
void log_close_file (void)
 
bool log_check_level (uint8_t level, bool ignore_level)
 
int get_error_text (char *buf, int err)
 Get the error text object. More...
 
void print_to (uint8_t level, const char *file, uint32_t line, int err, const char *time_string, const char *err_text_buf, const char *format, va_list args)
 
void log_msg (uint8_t level, const char *file, uint32_t line, bool flush_std, bool ignore_level, int err, const char *format, va_list args)
 
void log_levels (uint8_t level, const char *file, uint32_t line, const char *format,...)
 
void log_errno_error (uint8_t level, const char *file, uint32_t line, const char *format,...)
 
void log_error_exit (uint8_t level, const char *file, uint32_t line, const char *format,...)
 
void log_error_exit_proc (uint8_t level, const char *file, uint32_t line, const char *format,...)
 
size_t printf_hex (char *buf, size_t buf_size, const uint8_t *data, size_t len, bool uppercase)
 Prints the data in data to buf as hex. More...
 

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200112L

◆ PRINT_COLOR

#define PRINT_COLOR (   stream,
  time,
  color,
  name,
  err,
  file,
  line 
)
Value:
fprintf(stream, "%s %s%-5s\x1b[0m%s\x1b[0m \x1b[90m%s:%d:\x1b[0m ", time, \
color, name, err, file, line)
T fprintf(T... args)
bool color
Definition: log.c:60

◆ PRINT_NO_COLOR

#define PRINT_NO_COLOR (   stream,
  time,
  color,
  name,
  err,
  file,
  line 
)     fprintf(stream, "%s %-5s%s %s:%d: ", time, name, err, file, line)

Function Documentation

◆ get_error_text()

int get_error_text ( char *  buf,
int  err 
)

Get the error text object.

Parameters
[out]bufString buffer of at least 30 chars
errerrno value passed to strerror()
Returns
The number of bytes written to buf, or 0 if buf is empty.

Warning, this function is non-threadsafe, as stderror() is not guaranteed to be threadsafe. Please make sure to uses mutxes/locks before calling this function.

◆ log_check_level()

bool log_check_level ( uint8_t  level,
bool  ignore_level 
)

◆ log_close_file()

void log_close_file ( void  )

◆ log_errno_error()

void log_errno_error ( uint8_t  level,
const char *  file,
uint32_t  line,
const char *  format,
  ... 
)

◆ log_error_exit()

void log_error_exit ( uint8_t  level,
const char *  file,
uint32_t  line,
const char *  format,
  ... 
)

◆ log_error_exit_proc()

void log_error_exit_proc ( uint8_t  level,
const char *  file,
uint32_t  line,
const char *  format,
  ... 
)

◆ log_levels()

void log_levels ( uint8_t  level,
const char *  file,
uint32_t  line,
const char *  format,
  ... 
)

◆ log_msg()

void log_msg ( uint8_t  level,
const char *  file,
uint32_t  line,
bool  flush_std,
bool  ignore_level,
int  err,
const char *  format,
va_list  args 
)

◆ log_open_file()

int log_open_file ( char *  path)

◆ log_set_color()

void log_set_color ( bool  enable)

◆ log_set_level()

void log_set_level ( uint8_t  level)

◆ log_set_lock()

void log_set_lock ( log_lock_fn  fn)

◆ log_set_meta()

void log_set_meta ( bool  enable)

◆ log_set_quiet()

void log_set_quiet ( bool  enable)

◆ print_to()

void print_to ( uint8_t  level,
const char *  file,
uint32_t  line,
int  err,
const char *  time_string,
const char *  err_text_buf,
const char *  format,
va_list  args 
)

◆ printf_hex()

size_t printf_hex ( char *  buf,
size_t  buf_size,
const uint8_t *  data,
size_t  len,
bool  uppercase 
)

Prints the data in data to buf as hex.

Prints the data in data to buf as hex.

Parameters
[out]bufThe output string buffer.
buf_sizeThe size of the output buffer, buf. As this will NUL terminated, make sure that this is an odd number, otherwise you may cut a hex-byte in half.
[in]dataThe input data to print to buf.
lenThe length of data.
uppercaseIf false, print hex in lowercase. If true, print hex in uppercase.
Returns
The number of hex characters that have been written to buf without truncation. This excludes the NUL-terminator.
Author
Jouni Malinen j@w1..nosp@m.fi
Author
Alexandru Mereacre
Remarks
Adapted from hostap's src/utils/common.c, see https://w1.fi/cgit/hostap/tree/src/utils/common.c?h=hostap_2_10#n317, except with additional NULL pointer checking.

Variable Documentation

◆ color

bool color

◆ level

uint8_t level

◆ lock

static void lock ( void  )

◆ logfp

FILE* logfp

◆ meta

bool meta

◆ quiet

bool quiet