summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-08-26 06:22:58 +0200
committerSven Gothel <[email protected]>2020-08-26 06:22:58 +0200
commitf75f6ba92bed201b80e578d3dd5e6c27a75c5710 (patch)
tree4e4a80fb2afa133b7865f071335af6efacd038cb
parent997c979f5fa83c111f790028f0fbcbb819970fad (diff)
dbt_debug.hpp: Ressurect ERR_PRINT and WARN_PRINT inline __FILE__ and __LINE__
-rw-r--r--api/direct_bt/dbt_debug.hpp17
-rw-r--r--src/direct_bt/dbt_debug.cpp30
2 files changed, 37 insertions, 10 deletions
diff --git a/api/direct_bt/dbt_debug.hpp b/api/direct_bt/dbt_debug.hpp
index 84929184..e5b5c9ff 100644
--- a/api/direct_bt/dbt_debug.hpp
+++ b/api/direct_bt/dbt_debug.hpp
@@ -31,6 +31,7 @@
#include <cstring>
#include <string>
#include <cstdio>
+#include <cstdarg>
extern "C" {
#include <errno.h>
@@ -58,11 +59,23 @@ namespace direct_bt {
#define PERF_TS_TD(m)
#endif
+ /** Use for unconditional error messages, prefix '[elapsed_time] Error @ file:line: '. Function also appends last errno and strerror(errno). */
+ void ERR_PRINTv(const char *file, const int line, const char * format, va_list args);
+
+ /** Use for unconditional error messages, prefix '[elapsed_time] Error @ file:line: '. Function also appends last errno and strerror(errno). */
+ void ERR_PRINT2(const char *file, const int line, const char * format, ...);
+
/** Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE: '. Function also appends last errno and strerror(errno). */
- void ERR_PRINT(const char * format, ...);
+ #define ERR_PRINT(...) { ERR_PRINT2(__FILE__, __LINE__, __VA_ARGS__); }
+
+ /** Use for unconditional warning messages, prefix '[elapsed_time] Warning @ file:line: ' */
+ void WARN_PRINTv(const char *file, const int line, const char * format, va_list args);
+
+ /** Use for unconditional warning messages, prefix '[elapsed_time] Warning @ file:line: ' */
+ void WARN_PRINT2(const char *file, const int line, const char * format, ...);
/** Use for unconditional warning messages, prefix '[elapsed_time] Warning @ FILE:LINE: ' */
- void WARN_PRINT(const char * format, ...);
+ #define WARN_PRINT(...) { WARN_PRINT2(__FILE__, __LINE__, __VA_ARGS__); }
/** Use for unconditional plain messages, prefix '[elapsed_time] '. */
void PLAIN_PRINT(const char * format, ...);
diff --git a/src/direct_bt/dbt_debug.cpp b/src/direct_bt/dbt_debug.cpp
index ec7fa520..8ef6f6ed 100644
--- a/src/direct_bt/dbt_debug.cpp
+++ b/src/direct_bt/dbt_debug.cpp
@@ -31,7 +31,7 @@ using namespace direct_bt;
void direct_bt::DBG_PRINT(const char * format, ...) {
if(direct_bt::DBTEnv::get().DEBUG) {
- fprintf(stderr, "[%'9" PRIu64 "] Debug: ", direct_bt::DBTEnv::getElapsedMillisecond());
+ fprintf(stderr, "[%'9" PRIu64 "] Debug: ", DBTEnv::getElapsedMillisecond());
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
@@ -43,7 +43,7 @@ void direct_bt::DBG_PRINT(const char * format, ...) {
void direct_bt::INFO_PRINT(const char * format, ...) {
if(direct_bt::DBTEnv::get().VERBOSE) {
- fprintf(stderr, "[%'9" PRIu64 "] Info: ", direct_bt::DBTEnv::getElapsedMillisecond());
+ fprintf(stderr, "[%'9" PRIu64 "] Info: ", DBTEnv::getElapsedMillisecond());
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
@@ -53,8 +53,15 @@ void direct_bt::INFO_PRINT(const char * format, ...) {
}
}
-void direct_bt::ERR_PRINT(const char * format, ...) {
- fprintf(stderr, "[%'9" PRIu64 "] Error @ %s:%d: ", direct_bt::DBTEnv::getElapsedMillisecond(), __FILE__, __LINE__);
+void direct_bt::ERR_PRINTv(const char *file, const int line, const char * format, va_list args) {
+ fprintf(stderr, "[%'9" PRIu64 "] Error @ %s:%d: ", DBTEnv::getElapsedMillisecond(), file, line);
+ vfprintf(stderr, format, args);
+ fprintf(stderr, "; last errno %d %s\n", errno, strerror(errno));
+ fflush(stderr);
+}
+
+void direct_bt::ERR_PRINT2(const char *file, const int line, const char * format, ...) {
+ fprintf(stderr, "[%'9" PRIu64 "] Error @ %s:%d: ", DBTEnv::getElapsedMillisecond(), file, line);
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
@@ -63,8 +70,15 @@ void direct_bt::ERR_PRINT(const char * format, ...) {
fflush(stderr);
}
-void direct_bt::WARN_PRINT(const char * format, ...) {
- fprintf(stderr, "[%'9" PRIu64 "] Warning @ %s:%d: ", direct_bt::DBTEnv::getElapsedMillisecond(), __FILE__, __LINE__);
+void direct_bt::WARN_PRINTv(const char *file, const int line, const char * format, va_list args) {
+ fprintf(stderr, "[%'9" PRIu64 "] Warning @ %s:%d: ", DBTEnv::getElapsedMillisecond(), file, line);
+ vfprintf(stderr, format, args);
+ fprintf(stderr, "\n");
+ fflush(stderr);
+}
+
+void direct_bt::WARN_PRINT2(const char *file, const int line, const char * format, ...) {
+ fprintf(stderr, "[%'9" PRIu64 "] Warning @ %s:%d: ", DBTEnv::getElapsedMillisecond(), file, line);
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
@@ -74,7 +88,7 @@ void direct_bt::WARN_PRINT(const char * format, ...) {
}
void direct_bt::PLAIN_PRINT(const char * format, ...) {
- fprintf(stderr, "[%'9" PRIu64 "] ", direct_bt::DBTEnv::getElapsedMillisecond());
+ fprintf(stderr, "[%'9" PRIu64 "] ", DBTEnv::getElapsedMillisecond());
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
@@ -85,7 +99,7 @@ void direct_bt::PLAIN_PRINT(const char * format, ...) {
void direct_bt::COND_PRINT(const bool condition, const char * format, ...) {
if( condition ) {
- fprintf(stderr, "[%'9" PRIu64 "] ", direct_bt::DBTEnv::getElapsedMillisecond());
+ fprintf(stderr, "[%'9" PRIu64 "] ", DBTEnv::getElapsedMillisecond());
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);