COMMON_SRCS = $(UTILITY_SRCS) $(PROBE_SRCS)
UTILITY_SRCS = \
+ ./helper/log.c \
./helper/lsan_open.c \
./helper/libdaprobe.c \
./helper/dahelper.c \
*
*/
+#include <log.h>
#include <unistd.h>
#include "da_gles20.h"
#include "binproto.h"
snprintf(error_msg, sizeof(error_msg), "%s : [%s], %s\n", msg,
func_name, lib_name);
perror(error_msg);
- PRINTERR(error_msg);
+ LOGE("%s", error_msg);
//wait for flush
sleep(1);
exit(0);
#define MINIMUM(X, Y) (((X) < (Y)) ? (X) : (Y))
-static bool do_send(int fd, void *data, size_t len, int flags)
+static bool do_send(int fd, const void *data, size_t len, int flags)
{
const size_t CHUNK_SIZE = 1024;
return !len;
}
-static void do_msg_send(int fd, enum AppMessageType type, void *data,
- size_t len)
+static void do_msg_send(int fd, enum AppMessageType type,
+ const void *data, size_t len)
{
struct msg_header {
int type;
do_send(fd, data, len, MSG_NOSIGNAL);
}
-void msg_send(enum AppMessageType type, void *data, size_t len)
+void msg_send(enum AppMessageType type, const void *data, size_t len)
{
int fd = gTraceInfo.socket.daemonSock;
pthread_mutex_t *mutex = &gTraceInfo.socket.sockMutex;
--- /dev/null
+#include <log.h>
+#include <daprobe.h>
+#include <stdarg.h>
+
+
+static enum AppMessageType log_level2msg_type(enum log_level level)
+{
+ switch (level) {
+ case LL_INFO: return APP_MSG_MSG;
+ case LL_WARN: return APP_MSG_WARNING;
+ case LL_ERROR: return APP_MSG_ERROR;
+ }
+
+ /* If the log level is incorrect, returns the type of error message */
+ return APP_MSG_ERROR;
+}
+
+void vraw_log(enum log_level level, const char *format, va_list args)
+{
+ char buf[1024];
+ const size_t buf_size = sizeof(buf);
+
+ int n = vsnprintf(buf, buf_size, format, args);
+ if (n > 0) {
+ if ((size_t)n < buf_size) {
+ /* Success */
+ enum AppMessageType msg_type = log_level2msg_type(level);
+ msg_send(msg_type, buf, n);
+ } else {
+ const char error_msg[] = "Log message is very log";
+ msg_send(APP_MSG_ERROR, error_msg, sizeof(error_msg));
+ }
+ } else {
+ const char error_msg[] = "Failed to create log message";
+ msg_send(APP_MSG_ERROR, error_msg, sizeof(error_msg));
+ }
+}
+
+void raw_log(enum log_level level, const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ vraw_log(level, format, args);
+ va_end(args);
+}
#ifndef __DAPROBE_H__
#define __DAPROBE_H__
+#include <log.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
const char *format, ...);
bool print_log_str(int msgType, char *st);
bool printLog(log_t* log, int msgType);
-void msg_send(enum AppMessageType type, void *data, size_t len);
+void msg_send(enum AppMessageType type, const void *data, size_t len);
void *rtdl_next(const char *symname);
void *rtld_default(const char *symname);
symbol = rtld_default(sname); \
} while (0)
-// ========================= print log =====================================
-#define PRINTMSG(...) \
- print_log_fmt(APP_MSG_MSG, __FUNCTION__, __LINE__, __VA_ARGS__)
-#define PRINTWRN(...) \
- print_log_fmt(APP_MSG_WARNING, __FUNCTION__, __LINE__, __VA_ARGS__)
-#define PRINTERR(...) \
- print_log_fmt(APP_MSG_ERROR, __FUNCTION__, __LINE__, __VA_ARGS__)
+// ========================== legacy log format ===============================
+#define PRINTMSG(FORMAT, ...) LOGI(FORMAT, ##__VA_ARGS__)
+#define PRINTWRN(FORMAT, ...) LOGW(FORMAT, ##__VA_ARGS__)
+#define PRINTERR(FORMAT, ...) LOGE(FORMAT, ##__VA_ARGS__)
+
#define INIT_INFO \
info.host_ip = 0; \
--- /dev/null
+#ifndef LOG_H
+#define LOG_H
+
+#include <stdarg.h>
+#include <dahelper.h> // for _getpid(), _gettid()
+
+enum log_level {
+ LL_INFO,
+ LL_WARN,
+ LL_ERROR,
+};
+
+void vraw_log(enum log_level level, const char *format, va_list args);
+void raw_log(enum log_level level, const char *format, ...);
+
+#define DO_RAW_LOG(LEVEL, FORMAT, ...) \
+ raw_log(LEVEL, "[%05d:%05d]%s:%d)" FORMAT, _getpid(), _gettid(), __func__, __LINE__, ##__VA_ARGS__)
+
+#define LOGI(FORMAT, ...) DO_RAW_LOG(LL_INFO, FORMAT, ##__VA_ARGS__)
+#define LOGW(FORMAT, ...) DO_RAW_LOG(LL_WARN, FORMAT, ##__VA_ARGS__)
+#define LOGE(FORMAT, ...) DO_RAW_LOG(LL_ERROR, FORMAT, ##__VA_ARGS__)
+
+#endif // LOG_H
#include "probe_event.h"
-
-#define LOGW PRINTWRN
-
#define MAX_INFO1_LEN 64
/* START - pack for gestures */