Rizin
unix-like reverse engineering framework and cli tools
rz_log.h
Go to the documentation of this file.
1 #ifndef RZ_LOG_H
2 #define RZ_LOG_H
3 
4 #include <rz_types.h>
5 #include <rz_userconf.h>
6 
7 #if (defined(_WIN32) || defined(_WIN64)) && !defined(__GNUC__)
8 #define MACRO_LOG_FUNC __FUNCTION__
9 // TODO: Windows weak symbols?
10 #elif defined(__EMSCRIPTEN__) // TODO: test upon Emscripten's version once it supports weak symbols
11 #define MACRO_LOG_FUNC __func__
12 #else
13 #define MACRO_LOG_FUNC __func__
14 #endif
15 
16 typedef enum rz_log_level {
23  RZ_LOGLVL_FATAL = 6, // This will call rz_sys_breakpoint() and trap the process for debugging!
24  RZ_LOGLVL_NONE = 0xFF
26 
27 #if RZ_CHECKS_LEVEL >= 2
28 #define RZ_DEFAULT_LOGLVL RZ_LOGLVL_WARN
29 #else
30 #define RZ_DEFAULT_LOGLVL RZ_LOGLVL_ERROR
31 #endif
32 
33 typedef void (*RzLogCallback)(const char *output, const char *funcname, const char *filename,
34  ut32 lineno, RzLogLevel level, const char *tag, const char *fmtstr, ...) RZ_PRINTF_CHECK(7, 8);
35 
36 #define RZ_VLOG(lvl, tag, fmtstr, args) rz_vlog(MACRO_LOG_FUNC, __FILE__, \
37  __LINE__, lvl, tag, fmtstr, args);
38 
39 #define RZ_LOG(lvl, tag, fmtstr, ...) rz_log(MACRO_LOG_FUNC, __FILE__, \
40  __LINE__, lvl, tag, fmtstr, ##__VA_ARGS__);
41 
42 #if RZ_BUILD_DEBUG
43 #define RZ_LOG_SILLY(fmtstr, ...) rz_log(MACRO_LOG_FUNC, __FILE__, \
44  __LINE__, RZ_LOGLVL_SILLY, NULL, fmtstr, ##__VA_ARGS__);
45 #define RZ_LOG_DEBUG(fmtstr, ...) rz_log(MACRO_LOG_FUNC, __FILE__, \
46  __LINE__, RZ_LOGLVL_DEBUG, NULL, fmtstr, ##__VA_ARGS__);
47 #else
48 #define RZ_LOG_SILLY(fmtstr, ...)
49 #define RZ_LOG_DEBUG(fmtstr, ...)
50 #endif
51 
52 #define RZ_LOG_VERBOSE(fmtstr, ...) rz_log(MACRO_LOG_FUNC, __FILE__, \
53  __LINE__, RZ_LOGLVL_VERBOSE, NULL, fmtstr, ##__VA_ARGS__);
54 #define RZ_LOG_INFO(fmtstr, ...) rz_log(MACRO_LOG_FUNC, __FILE__, \
55  __LINE__, RZ_LOGLVL_INFO, NULL, fmtstr, ##__VA_ARGS__);
56 #define RZ_LOG_WARN(fmtstr, ...) rz_log(MACRO_LOG_FUNC, __FILE__, \
57  __LINE__, RZ_LOGLVL_WARN, NULL, fmtstr, ##__VA_ARGS__);
58 #define RZ_LOG_ERROR(fmtstr, ...) rz_log(MACRO_LOG_FUNC, __FILE__, \
59  __LINE__, RZ_LOGLVL_ERROR, NULL, fmtstr, ##__VA_ARGS__);
60 #define RZ_LOG_FATAL(fmtstr, ...) rz_log(MACRO_LOG_FUNC, __FILE__, \
61  __LINE__, RZ_LOGLVL_FATAL, NULL, fmtstr, ##__VA_ARGS__);
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
67 // Called by rz_core to set the configuration variables
69 RZ_API void rz_log_set_file(const char *filename);
70 RZ_API void rz_log_set_srcinfo(bool show_info);
71 RZ_API void rz_log_set_colors(bool show_colors);
73 
74 // Functions for adding log callbacks
77 // TODO: rz_log_get_callbacks()
78 
79 /* Define rz_log as weak so it can be 'overwritten' externally
80  This allows another method of output redirection on POSIX (Windows?)
81  You can override this function to handle all logging logic / output yourself */
82 RZ_API void rz_log(const char *funcname, const char *filename,
83  ut32 lineno, RzLogLevel level, const char *tag, const char *fmtstr, ...) RZ_PRINTF_CHECK(6, 7);
84 
85 RZ_API void rz_vlog(const char *funcname, const char *filename,
86  ut32 lineno, RzLogLevel level, const char *tag, const char *fmtstr, va_list args);
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif // RZ_LOG_H
#define RZ_API
uint32_t ut32
const char * filename
Definition: ioapi.h:137
#define const
Definition: ansidecl.h:240
int args
Definition: mipsasm.c:18
RZ_API void rz_log_set_file(const char *filename)
Definition: log.c:37
RZ_API void rz_log_set_level(RzLogLevel level)
Definition: log.c:29
RZ_API void rz_log_set_traplevel(RzLogLevel level)
Definition: log.c:33
RZ_API void rz_log(const char *funcname, const char *filename, ut32 lineno, RzLogLevel level, const char *tag, const char *fmtstr,...) RZ_PRINTF_CHECK(6
enum rz_log_level RzLogLevel
RZ_API void rz_log_del_callback(RzLogCallback cbfunc)
Remove a logging callback.
Definition: log.c:67
RZ_API void RZ_API void rz_vlog(const char *funcname, const char *filename, ut32 lineno, RzLogLevel level, const char *tag, const char *fmtstr, va_list args)
Definition: log.c:73
rz_log_level
Definition: rz_log.h:16
@ RZ_LOGLVL_SILLY
Definition: rz_log.h:17
@ RZ_LOGLVL_NONE
Definition: rz_log.h:24
@ RZ_LOGLVL_WARN
Definition: rz_log.h:21
@ RZ_LOGLVL_INFO
Definition: rz_log.h:20
@ RZ_LOGLVL_ERROR
Definition: rz_log.h:22
@ RZ_LOGLVL_VERBOSE
Definition: rz_log.h:19
@ RZ_LOGLVL_FATAL
Definition: rz_log.h:23
@ RZ_LOGLVL_DEBUG
Definition: rz_log.h:18
RZ_API void rz_log_set_srcinfo(bool show_info)
Definition: log.c:42
RZ_API void rz_log_add_callback(RzLogCallback cbfunc)
Add a logging callback.
Definition: log.c:54
void(* RzLogCallback)(const char *output, const char *funcname, const char *filename, ut32 lineno, RzLogLevel level, const char *tag, const char *fmtstr,...) RZ_PRINTF_CHECK(7
Definition: rz_log.h:33
RZ_API void rz_log_set_colors(bool show_colors)
Definition: log.c:46
#define RZ_PRINTF_CHECK(fmt, dots)
Definition: rz_types.h:192
static int level
Definition: vmenus.c:2424
diff_output_t output
Definition: zipcmp.c:237