55 lines
1.3 KiB
C
55 lines
1.3 KiB
C
#ifndef _OAUTH2LIB_LOG_
|
|
#define _OAUTH2LIB_LOG_
|
|
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
|
|
enum LOG_LEVEL {
|
|
LOG_ERR,
|
|
LOG_WARN,
|
|
LOG_INFO,
|
|
LOG_DEBUG,
|
|
LOG_TRACE,
|
|
};
|
|
|
|
enum LOG_LOC_TYPE {
|
|
LOG_LOC_TYPE_DISABLED,
|
|
LOG_LOC_TYPE_FS,
|
|
LOG_LOC_TYPE_STDS
|
|
};
|
|
|
|
struct log_loc {
|
|
enum LOG_LOC_TYPE type;
|
|
FILE* location;
|
|
const char* file_name;
|
|
bool keep_file_open;
|
|
};
|
|
|
|
#define LOG_LOC_FILE(file_location, keep_open) ((struct log_loc) { .type=LOG_LOC_TYPE_FS, .location=NULL, .file_name=file_location, .keep_file_open=keep_open })
|
|
#define LOG_LOC_STDS(stream) ((struct log_loc) { .type=LOG_LOC_TYPE_STDS, .location=stream, .file_name=NULL })
|
|
#define LOG_LOC_NONE() ((struct log_loc) { .type=LOG_LOC_TYPE_DISABLED })
|
|
|
|
struct log_config_s {
|
|
struct log_loc loc_error;
|
|
struct log_loc loc_warn;
|
|
struct log_loc loc_info;
|
|
struct log_loc loc_debug;
|
|
struct log_loc loc_trace;
|
|
|
|
bool timestamp;
|
|
};
|
|
|
|
struct logger_s {
|
|
const char* module_name;
|
|
struct log_config_s config;
|
|
};
|
|
|
|
void log_set_default_config(struct log_config_s config);
|
|
struct log_config_s* log_get_config(const char* module_name);
|
|
|
|
void log_log(const char* module, enum LOG_LEVEL log_level, const char* fmt, ...);
|
|
|
|
void log_log_ssl_err(const char* module, enum LOG_LEVEL log_level, const char* message_fmt, ...);
|
|
|
|
#endif //_OAUTH2LIB_LOG_
|