EDGESEC
0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
|
File containing the implementation of the logging functions. More...
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
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... | |
File containing the implementation of the logging functions.
File containing the definition of the logging functions.
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.
#define __FILENAME__ strrchr("/" __FILE__, '/') + 1 |
#define LEVEL_COLORS { "\x1b[94m", "\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[31m" } |
#define LEVEL_NAMES { "TRACE", "DEBUG", "INFO", "WARN", "ERROR" } |
#define log_debug | ( | ... | ) | log_levels(LOGC_DEBUG, __FILENAME__, __LINE__, __VA_ARGS__) |
#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__) |
#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)
#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.
#define log_info | ( | ... | ) | log_levels(LOGC_INFO, __FILENAME__, __LINE__, __VA_ARGS__) |
#define log_trace | ( | ... | ) | log_levels(LOGC_TRACE, __FILENAME__, __LINE__, __VA_ARGS__) |
#define LOG_VERSION "0.1.0" |
#define log_warn | ( | ... | ) | log_levels(LOGC_WARN, __FILENAME__, __LINE__, __VA_ARGS__) |
#define MAX_LOG_LEVELS 5 |
#define PRINTF_FORMAT | ( | a, | |
b | |||
) |
typedef void(* log_lock_fn) (bool lock) |
void log_close_file | ( | void | ) |
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, | ||
... | |||
) |
void log_levels | ( | uint8_t | level, |
const char * | file, | ||
uint32_t | line, | ||
const char * | format, | ||
... | |||
) |
int log_open_file | ( | char * | path | ) |
void log_set_color | ( | bool | enable | ) |
void log_set_level | ( | uint8_t | level | ) |
void log_set_lock | ( | log_lock_fn | fn | ) |
void log_set_meta | ( | bool | enable | ) |
void log_set_quiet | ( | bool | enable | ) |
void log_set_udata | ( | void * | udata | ) |
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.
[out] | buf | The output string buffer. |
buf_size | The 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] | data | The input data to print to buf . |
len | The length of data . | |
uppercase | If false , print hex in lowercase. If true , print hex in uppercase. |
buf
without truncation. This excludes the NUL
-terminator.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.