Concord - C Discord API library
A Discord API wrapper library written in C
log.h
Go to the documentation of this file.
1/* Edited by Lucas Müller https://github.com/lcsmuller */
9#ifndef LOG_H
10#define LOG_H
11
12#include <stdio.h>
13#include <stdarg.h>
14#include <stdbool.h>
15#include <time.h>
16
17#define LOG_VERSION "x.x.x modified"
18
19typedef struct {
20 va_list ap;
21 const char *fmt;
22 const char *file;
23 struct tm *time;
24 void *udata;
25 int line;
26 int level;
27} log_Event;
28
29typedef void (*log_LogFn)(log_Event *ev);
30typedef void (*log_LockFn)(bool lock, void *udata);
31
32#define LOG_MAX_CALLBACKS 32
33
34typedef struct {
36 void *udata;
37 int level;
39
40typedef struct {
41 void *udata;
43 int level;
44 bool quiet;
47
49
50#define log_trace(...) log_log(LOG_TRACE, __FILE__, __LINE__, __VA_ARGS__)
51#define log_debug(...) log_log(LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
52#define log_info(...) log_log(LOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
53#define log_warn(...) log_log(LOG_WARN, __FILE__, __LINE__, __VA_ARGS__)
54#define log_error(...) log_log(LOG_ERROR, __FILE__, __LINE__, __VA_ARGS__)
55#define log_fatal(...) log_log(LOG_FATAL, __FILE__, __LINE__, __VA_ARGS__)
56
57const char* log_level_string(int level);
58#define log_set_lock(fn, udata) _log_set_lock(&L, fn, udata);
59#define log_set_level(level) _log_set_level(&L, level);
60#define log_set_quiet(enable) _log_set_quiet(&L, enable)
61#define log_add_callback(fn, udata, level) _log_add_callback(&L, fn, udata, level)
62#define log_add_fp(fn, level) _log_add_fp(&L, fn, level)
63#define log_log(level, file, line, ...) _log_log(&L, level, file, line, __VA_ARGS__)
64
65void _log_set_lock(log_Logger *L, log_LockFn fn, void *udata);
66void _log_set_level(log_Logger *L, int level);
67void _log_set_quiet(log_Logger *L, bool enable);
68int _log_add_callback(log_Logger *L, log_LogFn fn, void *udata, int level);
69int _log_add_fp(log_Logger *L, FILE *fp, int level);
70void _log_log(log_Logger *L, int level, const char *file, int line, const char *fmt, ...);
71
72extern const char *level_strings[];
73extern const char *level_colors[];
74extern log_Logger L;
75
76#endif
void(* log_LogFn)(log_Event *ev)
Definition: log.h:29
void(* log_LockFn)(bool lock, void *udata)
Definition: log.h:30
log_Level
Definition: log.h:48
#define LOG_MAX_CALLBACKS
log_Logger L
const char * log_level_string(int level)
const char * level_strings[]
void _log_set_quiet(log_Logger *L, bool enable)
int _log_add_callback(log_Logger *L, log_LogFn fn, void *udata, int level)
int _log_add_fp(log_Logger *L, FILE *fp, int level)
void _log_set_level(log_Logger *L, int level)
const char * level_colors[]
void _log_log(log_Logger *L, int level, const char *file, int line, const char *fmt,...)
void _log_set_lock(log_Logger *L, log_LockFn fn, void *udata)
@ LOG_ERROR
Definition: log.h:48
@ LOG_TRACE
Definition: log.h:48
@ LOG_INFO
Definition: log.h:48
@ LOG_DEBUG
Definition: log.h:48
@ LOG_FATAL
Definition: log.h:48
@ LOG_WARN
Definition: log.h:48
Definition: log.h:34
log_LogFn fn
Definition: log.h:35
int level
Definition: log.h:37
void * udata
Definition: log.h:36
Definition: log.h:19
const char * fmt
Definition: log.h:21
int level
Definition: log.h:26
void * udata
Definition: log.h:24
struct tm * time
Definition: log.h:23
const char * file
Definition: log.h:22
va_list ap
Definition: log.h:20
int line
Definition: log.h:25
Definition: log.h:40
bool quiet
Definition: log.h:44
int level
Definition: log.h:43
void * udata
Definition: log.h:41
log_LockFn lock
Definition: log.h:42