Skip to content

Commit

Permalink
logger: begin adding macros for easier access
Browse files Browse the repository at this point in the history
  • Loading branch information
postables committed Aug 8, 2020
1 parent 30cbdaf commit 64baf37
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 16 additions & 0 deletions include/thirdparty/logger/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@
#include <string.h>

#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define LOG_INFO(thl, fd, msg) \
thl->log(thl, fd, msg, LOG_LEVELS_INFO, __FILENAME__, __LINE__);
#define LOG_WARN(thl, fd, msg) \
thl->log(thl, fd, msg, LOG_LEVELS_WARN, __FILENAME__, __LINE__);
#define LOG_ERROR(thl, fd, msg) \
thl->log(thl, fd, msg, LOG_LEVELS_ERROR, __FILENAME__, __LINE__);
#define LOG_DEBUG(thl, fd, msg) \
thl->log(thl, fd, msg, LOG_LEVELS_DEBUG, __FILENAME__, __LINE__);
#define LOGF_INFO(thl, fd, msg, ...) \
thl->logf(thl, fd, LOG_LEVELS_INFO, __FILENAME__, __LINE__, msg, __VA_ARGS__);
#define LOGF_WARN(thl, fd, msg, ...) \
thl->logf(thl, fd, LOG_LEVELS_WARN, __FILENAME__, __LINE__, msg, __VA_ARGS__);
#define LOGF_ERROR(thl, fd, msg, ...) \
thl->logf(thl, fd, LOG_LEVELS_ERROR, __FILENAME__, __LINE__, msg, __VA_ARGS__);
#define LOGF_DEBUG(thl, fd, msg, ...) \
thl->logf(thl, fd, LOG_LEVELS_DEBUG, __FILENAME__, __LINE__, msg, __VA_ARGS__);

/*! @struct base struct used by the thread_logger
*/
Expand Down
2 changes: 0 additions & 2 deletions thirdparty/logger/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,12 @@ void clear_file_logger(file_logger *fhl) {
char *get_time_string() {
char date[75];
strftime(date, sizeof date, "%b %d %r", localtime(&(time_t){time(NULL)}));
// 4 for [ ] and 1 for \0
char *msg = calloc(1, sizeof(date) + 1);
if (msg == NULL) {
printf("failed to calloc get_time_string\n");
return NULL;
}
strcat(msg, "");
strcat(msg, date);
// strcat(msg, "] ");
return msg;
}

0 comments on commit 64baf37

Please sign in to comment.