28
28
* as that of the covered work.
34
39
#include <pthread.h>
37
42
#include <android/log.h>
39
44
#include <syslog.h>
43
void log(const int, const char*, ...);
45
void setConsoleLog(bool);
46
void setDebugMode(bool);
48
* Print something, coloring it depending on the level
50
void logger(const int level, const char *format, ...);
53
* Allow writing on the console
55
void setConsoleLog(int c);
58
* When debug mode is not set, logging will not print anything
60
void setDebugMode(int d);
63
* Return the current mode
65
int getDebugMode(void);
68
* Thread-safe function to print the stringified contents of errno
51
#define LOG_FORMAT(M, ...) "%s:%d:0x%x: " M, FILE_NAME, __LINE__, (unsigned long) pthread_self() & 0xffff, ##__VA_ARGS__
72
#define LOG_FORMAT(M, ...) "%s:%d:0x%x: " M, FILE_NAME, __LINE__, \
73
(unsigned long) pthread_self() & 0xffff, \
53
76
#ifndef __ANDROID__
57
80
#define WARN(M, ...) LOGGER(M, LOG_WARNING, ##__VA_ARGS__)
58
81
#define INFO(M, ...) LOGGER(M, LOG_INFO, ##__VA_ARGS__)
59
82
#define DEBUG(M, ...) LOGGER(M, LOG_DEBUG, ##__VA_ARGS__)
60
#define LOGGER(M, LEVEL, ...) Logger::log(LEVEL, LOG_FORMAT(M, ##__VA_ARGS__))
83
#define LOGGER(M, LEVEL, ...) logger(LEVEL, LOG_FORMAT(M, ##__VA_ARGS__))
85
#else /* __ANDROID__ */
65
88
#define APP_NAME "libsflphone"
68
91
// Avoid printing whole path on android
69
#define FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
92
#define FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 \
71
95
#define ERROR(M, ...) LOGGER(M, ANDROID_LOG_ERROR, ##__VA_ARGS__)
72
96
#define WARN(M, ...) LOGGER(M, ANDROID_LOG_WARN, ##__VA_ARGS__)
73
97
#define INFO(M, ...) LOGGER(M, ANDROID_LOG_INFO, ##__VA_ARGS__)
74
98
#define DEBUG(M, ...) LOGGER(M, ANDROID_LOG_DEBUG, ##__VA_ARGS__)
75
99
#define LOGGER(M, LEVEL, ...) __android_log_print(LEVEL, APP_NAME, LOG_FORMAT(M, ##__VA_ARGS__))
100
#endif /* __ANDROID__ */
78
102
#define BLACK "\033[22;30m"
79
103
#define RED "\033[22;31m"