ulogger
athreadsafeloggerwithcoloredoutput
|
Go to the documentation of this file.
37 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
45 #define LOG_INFO(thl, msg) \
46 thl->log(thl, 0, msg, LOG_LEVELS_INFO, __FILENAME__, __LINE__);
54 #define LOG_WARN(thl, msg) \
55 thl->log(thl, 0, msg, LOG_LEVELS_WARN, __FILENAME__, __LINE__);
63 #define LOG_ERROR(thl, msg) \
64 thl->log(thl, 0, msg, LOG_LEVELS_ERROR, __FILENAME__, __LINE__);
73 #define LOG_DEBUG(thl, msg) \
74 thl->log(thl, 0, msg, LOG_LEVELS_DEBUG, __FILENAME__, __LINE__);
84 #define LOGF_INFO(thl, msg, ...) \
85 thl->logf(thl, 0, LOG_LEVELS_INFO, __FILENAME__, __LINE__, msg, __VA_ARGS__);
95 #define LOGF_WARN(thl, msg, ...) \
96 thl->logf(thl, 0, LOG_LEVELS_WARN, __FILENAME__, __LINE__, msg, __VA_ARGS__);
106 #define LOGF_ERROR(thl, msg, ...) \
107 thl->logf(thl, 0, LOG_LEVELS_ERROR, __FILENAME__, __LINE__, msg, __VA_ARGS__);
117 #define LOGF_DEBUG(thl, msg, ...) \
118 thl->logf(thl, 0, LOG_LEVELS_DEBUG, __FILENAME__, __LINE__, msg, __VA_ARGS__);
123 #define fLOG_INFO(fhl, msg) \
124 fhl->thl->log(fhl->thl, fhl->fd, msg, LOG_LEVELS_INFO, __FILENAME__, __LINE__);
129 #define fLOG_WARN(fhl, msg) \
130 fhl->thl->log(fhl->thl, fhl->fd, msg, LOG_LEVELS_WARN, __FILENAME__, __LINE__);
135 #define fLOG_ERROR(fhl, msg) \
136 fhl->thl->log(fhl->thl, fhl->fd, msg, LOG_LEVELS_ERROR, __FILENAME__, __LINE__);
141 #define fLOG_DEBUG(fhl, msg) \
142 fhl->thl->log(fhl->thl, fhl->fd, msg, LOG_LEVELS_DEBUG, __FILENAME__, __LINE__);
147 #define fLOGF_INFO(fhl, msg, ...) \
148 fhl->thl->logf(fhl->thl, fhl->fd, LOG_LEVELS_INFO, __FILENAME__, __LINE__, msg, __VA_ARGS__);
153 #define fLOGF_WARN(fhl, msg, ...) \
154 fhl->thl->logf(fhl->thl, fhl->fd, LOG_LEVELS_WARN, __FILENAME__, __LINE__, msg, __VA_ARGS__);
159 #define fLOGF_ERROR(fhl, msg, ...) \
160 fhl->thl->logf(fhl->thl, fhl->fd, LOG_LEVELS_ERROR, __FILENAME__, __LINE__, msg, __VA_ARGS__);
165 #define fLOGF_DEBUG(fhl, msg, ...) \
166 fhl->thl->logf(fhl->thl, fhl->fd, LOG_LEVELS_DEBUG, __FILENAME__, __LINE__, msg, __VA_ARGS__);
205 const char *message,
LOG_LEVELS level,
const char *file,
230 const char *message, ...);
241 LOG_LEVELS level,
char *file,
int line,
char *message, ...);
325 int line,
char *message, ...);
void clear_file_logger(file_logger *fhl)
free resources for the file ogger
struct thread_logger thread_logger
void clear_thread_logger(thread_logger *thl)
free resources for the threaded logger
void error_log(thread_logger *thl, int file_descriptor, char *message)
logs an error styled message - called by log_fn
file_logger * new_file_logger(char *output_file, bool with_debug)
returns a new file_logger Calls new_thread_logger internally
mutex_fn lock
used for synchronization across threads
void(* log_fnf)(struct thread_logger *thl, int file_descriptor, LOG_LEVELS level, char *file, int line, char *message,...)
thread_logger * thl
the file descriptor used for sending log information to
mutex_fn unlock
helper function for pthread_mutex_lock
log_fn log
helper function for pthread_mutex_unlock
log_fnf logf
function that gets called for all regular logging
void info_log(thread_logger *thl, int file_descriptor, char *message)
logs an info styled message - called by log_fn
void logf_func(thread_logger *thl, int file_descriptor, LOG_LEVELS level, char *file, int line, char *message,...)
like log_func but for formatted logs
pthread_mutex_t mutex
indicates whether we will action on debug logs
int write_file_log(int file_descriptor, char *message)
used to write a log message to file although this really means a file descriptor
void log_func(thread_logger *thl, int file_descriptor, char *message, LOG_LEVELS level, char *file, int line)
main function you should call, which will delegate to the appopriate *_log function
void(* log_fn)(struct thread_logger *thl, int file_descriptor, char *message, LOG_LEVELS level, char *file, int line)
macros and utilities for printing color to stdout from https://www.quora.com/How-do-I-print-a-colored...
thread_logger * new_thread_logger(bool with_debug)
returns a new thread safe logger if with_debug is false, then all debug_log calls will be ignored
struct file_logger file_logger
void get_time_string(char *date_buffer, size_t date_buffer_len)
returns a timestamp of format Jul 06 10:12:20 PM
void warn_log(thread_logger *thl, int file_descriptor, char *message)
logs a warned styled message - called by log_fn
void debug_log(thread_logger *thl, int file_descriptor, char *message)
logs a debug styled message - called by log_fn
int(* mutex_fn)(pthread_mutex_t *mx)