EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
Macros | Typedefs | Enumerations | Functions
log.h File Reference

File containing the implementation of the logging functions. More...

#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
Include dependency graph for log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LOG_VERSION   "0.1.0"
 
#define __FILENAME__   strrchr("/" __FILE__, '/') + 1
 
#define MAX_LOG_LEVELS   5
 
#define LEVEL_NAMES    { "TRACE", "DEBUG", "INFO", "WARN", "ERROR" }
 
#define LEVEL_COLORS    { "\x1b[94m", "\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[31m" }
 
#define PRINTF_FORMAT(a, b)
 
#define log_trace(...)    log_levels(LOGC_TRACE, __FILENAME__, __LINE__, __VA_ARGS__)
 
#define log_debug(...)    log_levels(LOGC_DEBUG, __FILENAME__, __LINE__, __VA_ARGS__)
 
#define log_info(...)   log_levels(LOGC_INFO, __FILENAME__, __LINE__, __VA_ARGS__)
 
#define log_warn(...)   log_levels(LOGC_WARN, __FILENAME__, __LINE__, __VA_ARGS__)
 
#define log_error(...)    log_levels(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)
 Logs an error message. Do not use this for if you want to log errno, instead use log_errno for this. More...
 
#define log_errno(...)    log_errno_error(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)
 Logs an error message using the value of errno. This should be used for errors that set errno (e.g. system errors) More...
 
#define log_err_ex(...)    log_error_exit(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)
 
#define log_err_exp(...)    log_error_exit_proc(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)
 

Typedefs

typedef void(* log_lock_fn) (bool lock)
 

Enumerations

enum  {
  LOGC_TRACE , LOGC_DEBUG , LOGC_INFO , LOGC_WARN ,
  LOGC_ERROR
}
 

Functions

void log_set_udata (void *udata)
 
void log_set_lock (log_lock_fn fn)
 
void log_set_level (uint8_t level)
 
void log_set_quiet (bool enable)
 
void log_set_color (bool enable)
 
void log_set_meta (bool enable)
 
int log_open_file (char *path)
 
void log_close_file (void)
 
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...
 

Detailed Description

File containing the implementation of the logging functions.

File containing the definition of the logging functions.

Authors
rxi, Alexandru Mereacre

Copyright (c) 2017 rxi

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See log.c for details.

Authors
rxi, Alexandru Mereacre

Macro Definition Documentation

◆ __FILENAME__

#define __FILENAME__   strrchr("/" __FILE__, '/') + 1

◆ LEVEL_COLORS

#define LEVEL_COLORS    { "\x1b[94m", "\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[31m" }

◆ LEVEL_NAMES

#define LEVEL_NAMES    { "TRACE", "DEBUG", "INFO", "WARN", "ERROR" }

◆ log_debug

#define log_debug (   ...)     log_levels(LOGC_DEBUG, __FILENAME__, __LINE__, __VA_ARGS__)

◆ log_err_ex

#define log_err_ex (   ...)     log_error_exit(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)

◆ log_err_exp

#define log_err_exp (   ...)     log_error_exit_proc(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)

◆ log_errno

#define log_errno (   ...)     log_errno_error(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)

Logs an error message using the value of errno. This should be used for errors that set errno (e.g. system errors)

◆ log_error

#define log_error (   ...)     log_levels(LOGC_ERROR, __FILENAME__, __LINE__, __VA_ARGS__)

Logs an error message. Do not use this for if you want to log errno, instead use log_errno for this.

◆ log_info

#define log_info (   ...)    log_levels(LOGC_INFO, __FILENAME__, __LINE__, __VA_ARGS__)

◆ log_trace

#define log_trace (   ...)     log_levels(LOGC_TRACE, __FILENAME__, __LINE__, __VA_ARGS__)

◆ LOG_VERSION

#define LOG_VERSION   "0.1.0"

◆ log_warn

#define log_warn (   ...)    log_levels(LOGC_WARN, __FILENAME__, __LINE__, __VA_ARGS__)

◆ MAX_LOG_LEVELS

#define MAX_LOG_LEVELS   5

◆ PRINTF_FORMAT

#define PRINTF_FORMAT (   a,
 
)

Typedef Documentation

◆ log_lock_fn

typedef void(* log_lock_fn) (bool lock)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
LOGC_TRACE 
LOGC_DEBUG 
LOGC_INFO 
LOGC_WARN 
LOGC_ERROR 

Function Documentation

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

◆ log_set_udata()

void log_set_udata ( void *  udata)

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