Skip to content

Commit

Permalink
use __FILE_NAME__ for logging instead of __FILE__
Browse files Browse the repository at this point in the history
  • Loading branch information
imyxh committed Jul 24, 2024
1 parent 38d56e9 commit abb902c
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions libaylp/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,31 @@
enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };

// adds trailing newline
#define log_trace(...) log_impl(LOG_TRACE, __FILE__, __LINE__, 1, __VA_ARGS__)
#define log_debug(...) log_impl(LOG_DEBUG, __FILE__, __LINE__, 1, __VA_ARGS__)
#define log_info(...) log_impl(LOG_INFO, __FILE__, __LINE__, 1, __VA_ARGS__)
#define log_warn(...) log_impl(LOG_WARN, __FILE__, __LINE__, 1, __VA_ARGS__)
#define log_error(...) log_impl(LOG_ERROR, __FILE__, __LINE__, 1, __VA_ARGS__)
#define log_fatal(...) log_impl(LOG_FATAL, __FILE__, __LINE__, 1, __VA_ARGS__)
#define log_trace(...) \
log_impl(LOG_TRACE, __FILE_NAME__, __LINE__, 1, __VA_ARGS__)
#define log_debug(...) \
log_impl(LOG_DEBUG, __FILE_NAME__, __LINE__, 1, __VA_ARGS__)
#define log_info(...) \
log_impl(LOG_INFO, __FILE_NAME__, __LINE__, 1, __VA_ARGS__)
#define log_warn(...) \
log_impl(LOG_WARN, __FILE_NAME__, __LINE__, 1, __VA_ARGS__)
#define log_error(...) \
log_impl(LOG_ERROR, __FILE_NAME__, __LINE__, 1, __VA_ARGS__)
#define log_fatal(...) \
log_impl(LOG_FATAL, __FILE_NAME__, __LINE__, 1, __VA_ARGS__)
// no trailing newline
#define logn_trace(...) log_impl(LOG_TRACE, __FILE__, __LINE__, 0, __VA_ARGS__)
#define logn_debug(...) log_impl(LOG_DEBUG, __FILE__, __LINE__, 0, __VA_ARGS__)
#define logn_info(...) log_impl(LOG_INFO, __FILE__, __LINE__, 0, __VA_ARGS__)
#define logn_warn(...) log_impl(LOG_WARN, __FILE__, __LINE__, 0, __VA_ARGS__)
#define logn_error(...) log_impl(LOG_ERROR, __FILE__, __LINE__, 0, __VA_ARGS__)
#define logn_fatal(...) log_impl(LOG_FATAL, __FILE__, __LINE__, 0, __VA_ARGS__)
#define logn_trace(...) \
log_impl(LOG_TRACE, __FILE_NAME__, __LINE__, 0, __VA_ARGS__)
#define logn_debug(...) \
log_impl(LOG_DEBUG, __FILE_NAME__, __LINE__, 0, __VA_ARGS__)
#define logn_info(...) \
log_impl(LOG_INFO, __FILE_NAME__, __LINE__, 0, __VA_ARGS__)
#define logn_warn(...) \
log_impl(LOG_WARN, __FILE_NAME__, __LINE__, 0, __VA_ARGS__)
#define logn_error(...) \
log_impl(LOG_ERROR, __FILE_NAME__, __LINE__, 0, __VA_ARGS__)
#define logn_fatal(...) \
log_impl(LOG_FATAL, __FILE_NAME__, __LINE__, 0, __VA_ARGS__)

void log_init(int level);
// returns true on success, false otherwise
Expand Down

0 comments on commit abb902c

Please sign in to comment.