diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-09-08 09:04:24 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-09-08 09:04:24 +0200 |
commit | 5e64d1c4b78c908e92a65e03fdc6817ffe59a8a6 (patch) | |
tree | 6472c8d0bf822c52b633804a39afc05351c0571b /src/log.h | |
parent | log: prepend timestamps (diff) | |
download | cimple-5e64d1c4b78c908e92a65e03fdc6817ffe59a8a6.tar.gz cimple-5e64d1c4b78c908e92a65e03fdc6817ffe59a8a6.zip |
log: refactoring
Diffstat (limited to '')
-rw-r--r-- | src/log.h | 42 |
1 files changed, 21 insertions, 21 deletions
@@ -34,49 +34,49 @@ static inline void log_prefix(FILE *dest) log_print_timestamp(dest); } -#define log_error_prefix() \ +#define log_err_prefix() \ do { \ log_prefix(stderr); \ fprintf(stderr, "%s(%d): ", basename(__FILE__), __LINE__); \ } while (0) -#define print_errno(s) \ +#define log(...) \ do { \ - log_error_prefix(); \ - perror(s); \ + log_prefix(stdout); \ + printf(__VA_ARGS__); \ } while (0) -#define check_errno(expr, s) \ +#define log_err(...) \ do { \ - int CONCAT(ret, __LINE__) = expr; \ - if (CONCAT(ret, __LINE__) < 0) \ - print_errno(s); \ + log_err_prefix(); \ + fprintf(stderr, __VA_ARGS__); \ } while (0) -#define pthread_print_errno(var, s) \ +#define log_errno(s) \ do { \ - errno = var; \ - print_errno(s); \ - var = -var; \ + log_err_prefix(); \ + perror(s); \ } while (0) -#define pthread_check(expr, s) \ +#define log_errno_if(expr, s) \ do { \ int CONCAT(ret, __LINE__) = expr; \ - if (CONCAT(ret, __LINE__)) \ - pthread_print_errno(CONCAT(ret, __LINE__), s); \ + if (CONCAT(ret, __LINE__) < 0) \ + log_errno(s); \ } while (0) -#define print_error(...) \ +#define pthread_errno(var, s) \ do { \ - log_error_prefix(); \ - fprintf(stderr, __VA_ARGS__); \ + errno = var; \ + log_errno(s); \ + var = -var; \ } while (0) -#define print_log(...) \ +#define pthread_errno_if(expr, s) \ do { \ - log_prefix(stdout); \ - printf(__VA_ARGS__); \ + int CONCAT(ret, __LINE__) = expr; \ + if (CONCAT(ret, __LINE__)) \ + pthread_errno(CONCAT(ret, __LINE__), s); \ } while (0) #endif |