1 #ifndef DEBUG_H
2 #define DEBUG_H
3 
4 #include <stdlib.h>
5 
6 #define EXIT_MALLOC  2 /* Malloc failure exit status. */
7 
8 /* uTox debug levels */
9 typedef enum {
10     LOG_LVL_OFF,
11     LOG_LVL_FATAL,
12     LOG_LVL_ERROR,      // This is really bad
13     LOG_LVL_WARNING,    // This is kinda bad
14     LOG_LVL_NOTICE,     // This is just something we should know about
15     LOG_LVL_INFO,       // This is what's happening
16     LOG_LVL_DEBUG,      // Something is broken, whats' happening everywhere
17     LOG_LVL_TRACE,      // I'm not kidding anymore... WHAT IS BROKEN?
18     LOG_LVL_NET_TRACE,  // OH, it's Toxcore that's broken? Whew!
19 } LOG_LVL;
20 
21 // returns current logging verbosity
22 int utox_verbosity();
23 
24 // define debugging macros in a platform specific way
25 
26 #ifdef __ANDROID__
27 #include "android/logging.h"
28 #else
29 void debug(const char *fmt, ...);
30 #endif
31 
32 #define VERB(x) (utox_verbosity() >= LOG_LVL_##x)
33 
34 #define LOG_FATAL_ERR(ex, file, str, ...) debug("\n\n%-14s:" str "\n\n", file ": ", ## __VA_ARGS__ ); exit(ex)
35 
36 #define LOG_ERR(file, str, ...)       (VERB(ERROR)     ? debug("%-14s" str "\n", file ": ", ## __VA_ARGS__ ) : ((void)(0)))
37 #define LOG_WARN(file, str, ...)      (VERB(WARNING)   ? debug("%-14s" str "\n", file ": ", ## __VA_ARGS__ ) : ((void)(0)))
38 #define LOG_NOTE(file, str, ...)      (VERB(NOTICE)    ? debug("%-14s" str "\n", file ": ", ## __VA_ARGS__ ) : ((void)(0)))
39 #define LOG_INFO(file, str, ...)      (VERB(INFO)      ? debug("%-14s" str "\n", file ": ", ## __VA_ARGS__ ) : ((void)(0)))
40 #define LOG_DEBUG(file, str, ...)     (VERB(DEBUG)     ? debug("%-14s" str "\n", file ": ", ## __VA_ARGS__ ) : ((void)(0)))
41 #define LOG_TRACE(file, str, ...)     (VERB(TRACE)     ? debug("%-14s" str "\n", file ": ", ## __VA_ARGS__ ) : ((void)(0)))
42 #define LOG_NET_TRACE(file, str, ...) (VERB(NET_TRACE) ? debug("%-14s" str "\n", file ": ", ## __VA_ARGS__ ) : ((void)(0)))
43 
44 // User requested
45 #define LOG_NORM(...)       (VERB(OFF) ? debug(__VA_ARGS__ ) : ((void)(0)))
46 
47 #endif // DEBUG_H
48