nndeploy C++ API  0.2.0
nndeploy C++ API
log.h
Go to the documentation of this file.
1 
2 
7 #ifndef _NNDEPLOY_BASE_LOG_H_
8 #define _NNDEPLOY_BASE_LOG_H_
9 
11 #include "nndeploy/base/macro.h"
12 
13 // NNDEPLOY_LOG
14 #ifdef __ANDROID__
15 #include <android/log.h>
16 #define NNDEPLOY_LOGDT(fmt, tag, ...) \
17  __android_log_print(ANDROID_LOG_DEBUG, tag, ("%s [File %s][Line %d] " fmt), \
18  __PRETTY_FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
19  fprintf(stdout, ("D/%s: %s [File %s][Line %d] " fmt), tag, \
20  __PRETTY_FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
21 #define NNDEPLOY_LOGIT(fmt, tag, ...) \
22  __android_log_print(ANDROID_LOG_INFO, tag, ("%s [File %s][Line %d] " fmt), \
23  __PRETTY_FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
24  fprintf(stdout, ("I/%s: %s [File %s][Line %d] " fmt), tag, \
25  __PRETTY_FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
26 #define NNDEPLOY_LOGET(fmt, tag, ...) \
27  __android_log_print(ANDROID_LOG_ERROR, tag, ("%s [File %s][Line %d] " fmt), \
28  __PRETTY_FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
29  fprintf(stderr, ("E/%s: %s [File %s][Line %d] " fmt), tag, \
30  __PRETTY_FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
31 #define NNDEPLOY_LOGWT(fmt, tag, ...) \
32  __android_log_print(ANDROID_LOG_ERROR, tag, ("%s [File %s][Line %d] " fmt), \
33  __PRETTY_FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
34  fprintf(stderr, ("E/%s: %s [File %s][Line %d] " fmt), tag, \
35  __PRETTY_FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
36 #define NNDEPLOY_PRINTFT(fmt, ...) \
37  __android_log_print(ANDROID_LOG_ERROR, "NNDEPLOY", fmt, ##__VA_ARGS__); \
38  fprintf(stdout, fmt, ##__VA_ARGS__)
39 #else
40 #define NNDEPLOY_LOGDT(fmt, tag, ...) \
41  fprintf(stdout, ("D/%s: %s [File %s][Line %d] " fmt), tag, __FUNCTION__, \
42  __FILE__, __LINE__, ##__VA_ARGS__)
43 #define NNDEPLOY_LOGIT(fmt, tag, ...) \
44  fprintf(stdout, ("I/%s: %s [File %s][Line %d] " fmt), tag, __FUNCTION__, \
45  __FILE__, __LINE__, ##__VA_ARGS__)
46 #define NNDEPLOY_LOGET(fmt, tag, ...) \
47  fprintf(stderr, ("E/%s: %s [File %s][Line %d] " fmt), tag, __FUNCTION__, \
48  __FILE__, __LINE__, ##__VA_ARGS__)
49 #define NNDEPLOY_LOGWT(fmt, tag, ...) \
50  fprintf(stderr, ("W/%s: %s [File %s][Line %d] " fmt), tag, __FUNCTION__, \
51  __FILE__, __LINE__, ##__VA_ARGS__)
52 #define NNDEPLOY_PRINTFT(fmt, ...) fprintf(stderr, (fmt), ##__VA_ARGS__)
53 #endif //__ANDROID__
54 
55 #define NNDEPLOY_LOGD(fmt, ...) \
56  NNDEPLOY_LOGDT(fmt, NNDEPLOY_DEFAULT_STR, ##__VA_ARGS__)
57 #define NNDEPLOY_LOGI(fmt, ...) \
58  NNDEPLOY_LOGIT(fmt, NNDEPLOY_DEFAULT_STR, ##__VA_ARGS__)
59 #define NNDEPLOY_LOGE(fmt, ...) \
60  NNDEPLOY_LOGET(fmt, NNDEPLOY_DEFAULT_STR, ##__VA_ARGS__)
61 #define NNDEPLOY_LOGW(fmt, ...) \
62  NNDEPLOY_LOGWT(fmt, NNDEPLOY_DEFAULT_STR, ##__VA_ARGS__)
63 #define NNDEPLOY_PRINTF(fmt, ...) NNDEPLOY_PRINTFT(fmt, ##__VA_ARGS__)
64 
65 #define NNDEPLOY_LOGE_IF(cond, fmt, ...) \
66  if (cond) { \
67  NNDEPLOY_LOGET(fmt, NNDEPLOY_DEFAULT_STR, ##__VA_ARGS__); \
68  }
69 
70 #endif // _NNDEPLOY_BASE_NNDEPLOY_LOG_