• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "trace.h"
2 
3 #include <hilog/log.h>
4 #include <memory.h>
5 #include <mutex>
6 #include <stdarg.h>
7 #include <stdio.h>
8 
9 #ifdef TRACE_ENABLE
10 static int level = 0;
11 static char space[20];
12 static std::mutex levelSpaceMutex;
13 #endif
14 
log_init()15 void log_init()
16 {
17 }
18 
log_printf(const char * label,const char * func,int line,const char * fmt,...)19 void log_printf(const char *label, const char *func, int line, const char *fmt, ...)
20 {
21     char str[4096];
22     va_list ap;
23     va_start(ap, fmt);
24     vsnprintf(str, sizeof(str), fmt, ap);
25     va_end(ap);
26 #ifdef TRACE_ENABLE
27     static std::mutex mutex;
28     std::lock_guard<std::mutex> lock(mutex);
29     OHOS::HiviewDFX::HiLog::Info({(LogType)3, 0, "Weston"}, "\033[31m%{public}-10s |"
30         " \033[33m%{public}-45s|\033[34m%{public}-5d\033[0m:%{public}s %{public}s\033[0m",
31         label, func, line, space, str);
32 #else
33     OHOS::HiviewDFX::HiLog::Info({(LogType)3, 0, "WAYLAND_SERVER"},
34         "%{public}s/%{public}s: %{public}s", label, func, str);
35 #endif
36 }
37 
log_enter(const char * label,const char * func,int line)38 void log_enter(const char *label, const char *func, int line)
39 {
40     log_enters(label, func, line, "");
41 }
42 
log_exit(const char * label,const char * func,int line)43 void log_exit(const char *label, const char *func, int line)
44 {
45     log_exits(label, func, line, "");
46 }
47 
log_enters(const char * LABEL,const char * func,int line,const char * str)48 void log_enters(const char *LABEL, const char *func, int line, const char *str)
49 {
50 #ifdef TRACE_ENABLE
51     std::lock_guard<std::mutex> lock(levelSpaceMutex);
52     _LOG(func, line, 33, "{ %s", str);
53     level++;
54     memset(space, ' ', sizeof(space));
55     space[level * 2] = 0;
56 #endif
57 }
58 
log_exits(const char * LABEL,const char * func,int line,const char * str)59 void log_exits(const char *LABEL, const char *func, int line, const char *str)
60 {
61 #ifdef TRACE_ENABLE
62     std::lock_guard<std::mutex> lock(levelSpaceMutex);
63     level--;
64     memset(space, ' ', sizeof(space));
65     space[level * 2] = 0;
66     _LOG(func, line, 33, "} %s", str);
67 #endif
68 }
69