Concord - C Discord API library
A Discord API wrapper library written in C
|
Go to the source code of this file.
Data Structures | |
struct | logconf_field |
The read-only config.json field. More... | |
struct | logconf_szbuf |
Generic sized-buffer. More... | |
struct | logconf |
A stackful and modularized wrapper over the popular 'log.c' facilities. More... | |
struct | loginfo |
Store logging information from log_http() More... | |
Macros | |
#define | __ERR(fmt, ...) log_fatal(fmt "%s", __VA_ARGS__) |
#define | ERR(...) |
Print error message and abort. More... | |
#define | ASSERT_S(expr, msg) |
Assert that allows printing a error message. More... | |
#define | VASSERT_S(expr, fmt, ...) |
Assert that allows printing a error message in a printf-like fashion. More... | |
#define | ANSICOLOR(str, color) str |
#define | ANSI_FG_BLACK "30" |
#define | ANSI_FG_RED "31" |
#define | ANSI_FG_GREEN "32" |
#define | ANSI_FG_YELLOW "33" |
#define | ANSI_FG_BLUE "34" |
#define | ANSI_FG_MAGENTA "35" |
#define | ANSI_FG_CYAN "36" |
#define | ANSI_FG_WHITE "37" |
#define | ANSI_FG_GRAY "90" |
#define | ANSI_FG_BRIGHT_RED "91" |
#define | ANSI_FG_BRIGHT_GREEN "92" |
#define | ANSI_FG_BRIGHT_YELLOW "93" |
#define | ANSI_FG_BRIGHT_BLUE "94" |
#define | ANSI_FG_BRIGHT_MAGENTA "95" |
#define | ANSI_FG_BRIGHT_CYAN "96" |
#define | ANSI_FG_BRIGHT_WHITE "97" |
#define | ANSI_BG_BLACK "40" |
#define | ANSI_BG_RED "41" |
#define | ANSI_BG_GREEN "42" |
#define | ANSI_BG_YELLOW "43" |
#define | ANSI_BG_BLUE "44" |
#define | ANSI_BG_MAGENTA "45" |
#define | ANSI_BG_CYAN "46" |
#define | ANSI_BG_WHITE "47" |
#define | ANSI_BG_GRAY "100" |
#define | ANSI_BG_BRIGHT_RED "101" |
#define | ANSI_BG_BRIGHT_GREEN "102" |
#define | ANSI_BG_BRIGHT_YELLOW "103" |
#define | ANSI_BG_BRIGHT_BLUE "104" |
#define | ANSI_BG_BRIGHT_MAGENTA "105" |
#define | ANSI_BG_BRIGHT_CYAN "106" |
#define | ANSI_BG_BRIGHT_WHITE "107" |
#define | logconf_trace(conf, ...) logconf_log(conf, LOG_TRACE, __FILE__, __LINE__, __VA_ARGS__) |
Log level trace. More... | |
#define | logconf_debug(conf, ...) logconf_log(conf, LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__) |
Log level debug. More... | |
#define | logconf_info(conf, ...) logconf_log(conf, LOG_INFO, __FILE__, __LINE__, __VA_ARGS__) |
Log level info. More... | |
#define | logconf_warn(conf, ...) logconf_log(conf, LOG_WARN, __FILE__, __LINE__, __VA_ARGS__) |
Log level warn. More... | |
#define | logconf_error(conf, ...) logconf_log(conf, LOG_ERROR, __FILE__, __LINE__, __VA_ARGS__) |
Log level error. More... | |
#define | logconf_fatal(conf, ...) logconf_log(conf, LOG_FATAL, __FILE__, __LINE__, __VA_ARGS__) |
Log level fatal. More... | |
#define | __logconf_log(conf, level, file, line, fmt, ...) |
#define | logconf_log(conf, level, file, line, ...) |
Run-time configurable log level. More... | |
#define | LOGCONF_ID_LEN 64 + 1 |
Functions | |
void | logconf_setup (struct logconf *conf, const char id[], FILE *fp) |
Initialize a struct logconf module from a config file. More... | |
void | logconf_branch (struct logconf *branch, struct logconf *orig, const char id[]) |
Branch and link a struct logconf module to a existing one. More... | |
void | logconf_cleanup (struct logconf *conf) |
Cleanup a struct logconf module. More... | |
struct logconf_field | logconf_get_field (struct logconf *conf, char *const path[], unsigned depth) |
Get the value from a given JSON field of the config file. More... | |
void | logconf_http (struct logconf *conf, struct loginfo *info, char url[], struct logconf_szbuf header, struct logconf_szbuf body, char label_fmt[],...) |
Log HTTP transfers. More... | |
void | logconf_set_lock (struct logconf *conf, log_LockFn fn, void *udata) |
If the log will be written to from multiple threads a lock function can be set. More... | |
void | logconf_set_level (struct logconf *conf, int level) |
Set the current logging level. More... | |
void | logconf_set_quiet (struct logconf *conf, bool enable) |
Toggle quiet mode. More... | |
void | logconf_add_callback (struct logconf *conf, log_LogFn fn, void *udata, int level) |
Callback functions called when logging data. More... | |
int | logconf_add_fp (struct logconf *conf, FILE *fp, int level) |
File where the log will be written. More... | |
#define __ERR | ( | fmt, | |
... | |||
) | log_fatal(fmt "%s", __VA_ARGS__) |
#define ERR | ( | ... | ) |
Print error message and abort.
... | printf-like format and variadic arguments (if any) |
#define ASSERT_S | ( | expr, | |
msg | |||
) |
Assert that allows printing a error message.
expr | conditional expression that's expected to be true |
msg | error message |
#define VASSERT_S | ( | expr, | |
fmt, | |||
... | |||
) |
Assert that allows printing a error message in a printf-like fashion.
expr | conditional expression that's expected to be true |
fmt | printf-like formatting string for the error message |
... | printf-like variadic arguments to be matched to fmt |
#define ANSICOLOR | ( | str, | |
color | |||
) | str |
#define ANSI_FG_BLACK "30" |
#define ANSI_FG_RED "31" |
#define ANSI_FG_GREEN "32" |
#define ANSI_FG_YELLOW "33" |
#define ANSI_FG_BLUE "34" |
#define ANSI_FG_MAGENTA "35" |
#define ANSI_FG_CYAN "36" |
#define ANSI_FG_WHITE "37" |
#define ANSI_FG_GRAY "90" |
#define ANSI_FG_BRIGHT_RED "91" |
#define ANSI_FG_BRIGHT_GREEN "92" |
#define ANSI_FG_BRIGHT_YELLOW "93" |
#define ANSI_FG_BRIGHT_BLUE "94" |
#define ANSI_FG_BRIGHT_MAGENTA "95" |
#define ANSI_FG_BRIGHT_CYAN "96" |
#define ANSI_FG_BRIGHT_WHITE "97" |
#define ANSI_BG_BLACK "40" |
#define ANSI_BG_RED "41" |
#define ANSI_BG_GREEN "42" |
#define ANSI_BG_YELLOW "43" |
#define ANSI_BG_BLUE "44" |
#define ANSI_BG_MAGENTA "45" |
#define ANSI_BG_CYAN "46" |
#define ANSI_BG_WHITE "47" |
#define ANSI_BG_GRAY "100" |
#define ANSI_BG_BRIGHT_RED "101" |
#define ANSI_BG_BRIGHT_GREEN "102" |
#define ANSI_BG_BRIGHT_YELLOW "103" |
#define ANSI_BG_BRIGHT_BLUE "104" |
#define ANSI_BG_BRIGHT_MAGENTA "105" |
#define ANSI_BG_BRIGHT_CYAN "106" |
#define ANSI_BG_BRIGHT_WHITE "107" |
#define logconf_trace | ( | conf, | |
... | |||
) | logconf_log(conf, LOG_TRACE, __FILE__, __LINE__, __VA_ARGS__) |
Log level trace.
conf | the struct logconf module |
... | the printf-like format string and successive arguments |
#define logconf_debug | ( | conf, | |
... | |||
) | logconf_log(conf, LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__) |
Log level debug.
conf | the struct logconf module |
... | the printf-like format string and successive arguments |
#define logconf_info | ( | conf, | |
... | |||
) | logconf_log(conf, LOG_INFO, __FILE__, __LINE__, __VA_ARGS__) |
Log level info.
conf | the struct logconf module |
... | the printf-like format string and successive arguments |
#define logconf_warn | ( | conf, | |
... | |||
) | logconf_log(conf, LOG_WARN, __FILE__, __LINE__, __VA_ARGS__) |
Log level warn.
conf | the struct logconf module |
... | the printf-like format string and successive arguments |
#define logconf_error | ( | conf, | |
... | |||
) | logconf_log(conf, LOG_ERROR, __FILE__, __LINE__, __VA_ARGS__) |
Log level error.
conf | the struct logconf module |
... | the printf-like format string and successive arguments |
#define logconf_fatal | ( | conf, | |
... | |||
) | logconf_log(conf, LOG_FATAL, __FILE__, __LINE__, __VA_ARGS__) |
Log level fatal.
conf | the struct logconf module |
... | the printf-like format string and successive arguments |
#define __logconf_log | ( | conf, | |
level, | |||
file, | |||
line, | |||
fmt, | |||
... | |||
) |
#define logconf_log | ( | conf, | |
level, | |||
file, | |||
line, | |||
... | |||
) |
Run-time configurable log level.
conf | the struct logconf module |
level | the log level enumerator from log.c |
file | the origin file name |
line | the origin file line |
... | the printf-like format string and successive arguments |
#define LOGCONF_ID_LEN 64 + 1 |
Maximum length for module id
void logconf_setup | ( | struct logconf * | conf, |
const char | id[], | ||
FILE * | fp | ||
) |
Initialize a struct logconf
module from a config file.
conf | pointer to the struct logconf structure to be initialized |
id | the struct logconf module id |
fp | the configuration file pointer that will fill struct logconf fields |
Branch and link a struct logconf
module to a existing one.
Initialize a branch
logging module thats expected to share common resources with its parent module orig
. The common resources include: config file directives, logging output and disabled modules list.
branch | pointer to the struct logconf structure to be initialized as orig branch |
orig | pointer to the struct logconf structure that holds the parent module |
id | the branch module id |
void logconf_cleanup | ( | struct logconf * | conf | ) |
Cleanup a struct logconf
module.
conf | the struct logconf structure to be cleaned |
struct logconf_field logconf_get_field | ( | struct logconf * | conf, |
char *const | path[], | ||
unsigned | depth | ||
) |
Get the value from a given JSON field of the config file.
conf | the struct logconf module |
path | the JSON key path |
depth | the path depth |
conf
with a config file void logconf_http | ( | struct logconf * | conf, |
struct loginfo * | info, | ||
char | url[], | ||
struct logconf_szbuf | header, | ||
struct logconf_szbuf | body, | ||
char | label_fmt[], | ||
... | |||
) |
Log HTTP transfers.
conf | the struct logconf module |
info | retrieve information on this logging |
url | the transfer URL |
header | the transfer header |
body | the transfer body |
label_fmt | a printf() like formatting string to provide additional logging description, such as the transfer's HTTP method, or HTTP response code. |
... | subsequent arguments that are converted for output |
void logconf_set_lock | ( | struct logconf * | conf, |
log_LockFn | fn, | ||
void * | udata | ||
) |
If the log will be written to from multiple threads a lock function can be set.
The function is passed the boolean true if the lock should be acquired or false if the lock should be released and the given udata value.
conf | the struct logconf module |
fn | lock callback |
udata | user arbitrary data |
void logconf_set_level | ( | struct logconf * | conf, |
int | level | ||
) |
Set the current logging level.
All logs below the given level will not be written to stderr. By default the level is LOG_TRACE, such that nothing is ignored.
conf | the struct logconf module |
level | logging level |
void logconf_set_quiet | ( | struct logconf * | conf, |
bool | enable | ||
) |
Toggle quiet mode.
Quiet-mode can be enabled by settings enable
to true
. While this mode is enabled the library will not output anything to stderr, but will continue to write to files and callbacks if any are set.
conf | the struct logconf module |
enable | true enables quiet-mode |
Callback functions called when logging data.
One or more callback functions which are called with the log data can be provided to the library. A callback function is passed a log_Event structure containing the line number, filename, fmt string, va printf va_list, level and the given udata.
conf | the struct logconf module |
fn | the callback function |
udata | user arbitrary data |
level | logging level to trigger callback |
int logconf_add_fp | ( | struct logconf * | conf, |
FILE * | fp, | ||
int | level | ||
) |
File where the log will be written.
One or more file pointers where the log will be written can be provided to the library. Any messages below the given level
are ignored. If the library failed to add a file pointer a value less-than-zero is returned.
conf | the struct logconf module |
fp | the write-to file pointer |
level | logging level condition for writing to fp |