Commit 5b53f2f9 authored by Tristan Matthews's avatar Tristan Matthews

* #27528: logger: add more info to android logging, cleanup macros

parent ded9dfeb
......@@ -31,10 +31,12 @@
#ifndef LOGGER_H_
#define LOGGER_H_
#include <syslog.h>
#include <pthread.h>
#ifdef __ANDROID__
#include <cstring>
#include <android/log.h>
#else
#include <syslog.h>
#endif
namespace Logger {
......@@ -45,22 +47,31 @@ void setDebugMode(bool);
bool getDebugMode();
};
#define LOGGER(M, LEVEL, ...) Logger::log(LEVEL, "%s:%d:tid %lu:\t" M, __FILE__, \
__LINE__, pthread_self() & 0xffff, ##__VA_ARGS__)
#define LOG_FORMAT(M) "%s:%d:0x%x: " M, FILE_NAME, __LINE__, (unsigned long) pthread_self() & 0xffff
#ifndef __ANDROID__
#define ERROR(M, ...) LOGGER(M, LOG_ERR, ##__VA_ARGS__)
#define FILE_NAME __FILE__
#define ERROR(M, ...) LOGGER(M, LOG_ERR, #__VA_ARGS__)
#define WARN(M, ...) LOGGER(M, LOG_WARNING, ##__VA_ARGS__)
#define INFO(M, ...) LOGGER(M, LOG_INFO, ##__VA_ARGS__)
#define DEBUG(M, ...) LOGGER(M, LOG_DEBUG, ##__VA_ARGS__)
#define LOGGER(M, LEVEL, ...) Logger::log(LEVEL, LOG_FORMAT(M), ##__VA_ARGS__)
#else /* ANDROID */
#ifndef APP_NAME
#define APP_NAME "libsflphone"
#endif
#define ERROR(M, ...) __android_log_print(ANDROID_LOG_ERROR, APP_NAME, M, ##__VA_ARGS__)
#define WARN(M, ...) __android_log_print(ANDROID_LOG_WARN, APP_NAME, M, ##__VA_ARGS__)
#define INFO(M, ...) __android_log_print(ANDROID_LOG_INFO, APP_NAME, M, ##__VA_ARGS__)
#define DEBUG(M, ...) __android_log_print(ANDROID_LOG_DEBUG, APP_NAME, M, ##__VA_ARGS__)
// Avoid printing whole path on android
#define FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define ERROR(M, ...) LOGGER(M, ANDROID_LOG_ERROR, ##__VA_ARGS__)
#define WARN(M, ...) LOGGER(M, ANDROID_LOG_WARN, ##__VA_ARGS__)
#define INFO(M, ...) LOGGER(M, ANDROID_LOG_INFO, ##__VA_ARGS__)
#define DEBUG(M, ...) LOGGER(M, ANDROID_LOG_DEBUG, ##__VA_ARGS__)
#define LOGGER(M, LEVEL, ...) __android_log_print(LEVEL, APP_NAME, LOG_FORMAT(M), ##__VA_ARGS__)
#endif /* ANDROID */
#define BLACK "\033[22;30m"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment