Lucciefr
Lua code caving, injection and exploration framework
log.h
Go to the documentation of this file.
1 
3 #ifndef LOG_H
4 #define LOG_H
5 
6 #include "bool.h"
7 #include "msgpack.h"
8 #include <stdio.h>
9 
11 typedef enum {
27 } LOG_LEVEL;
28 
30 typedef enum {
33 } LOG_NOTIFY;
34 
36 typedef void backend_callback_t(msgpack_sbuffer *logmsg, LOG_LEVEL level, void *userptr);
38 typedef void backend_command_t(LOG_NOTIFY reason, void *userptr);
39 
42 typedef struct {
45 
48  void *userptr;
49 
51  void *prev, *next;
53 
55  backend_command_t *notify, void *userptr);
56 void log_unregister_backend(backend_callback_t *callback, void *userptr);
57 
58 void log_shutdown(void);
59 void log_reset(bool with_checkpoints);
60 
61 /* DEPRECATED
62 void log_init(const char* filename);
63 void log_close(void);
64 void log_level(LOG_LEVEL level, const char* module, const char* fmt, ...);
65 */
66 
67 const char *log_level_string(LOG_LEVEL level);
68 
71 void attach_log_level(msgpack_object *attachment, LOG_LEVEL level,
72  const char *origin, const char *msg, int len);
73 void attach_log_level_ap(msgpack_object *attachment, LOG_LEVEL level,
74  const char *origin, const char *fmt, va_list ap);
75 void attach_log_level_fmt(msgpack_object *attachment, LOG_LEVEL level,
76  const char *origin, const char *fmt, ...);
78 
81 void log_scratch(const char *origin, const char *key, const char *value);
82 #define log_level(level, origin, msg) \
83  attach_log_level(NULL, level, origin, msg, -1)
84 #define log_level_ap(level, origin, fmt, ap) \
85  attach_log_level_ap(NULL, level, origin, fmt, ap)
86 #define log_level_fmt(level, origin, ...) \
87  attach_log_level_fmt(NULL, level, origin, __VA_ARGS__)
88 
92 #define attach_log_extra(attach, origin, ...) \
93  attach_log_level_fmt(attach, LOG_LEVEL_EXTRADEBUG, origin, __VA_ARGS__)
94 #define attach_log_debug(attach, origin, ...) \
95  attach_log_level_fmt(attach, LOG_LEVEL_DEBUG, origin, __VA_ARGS__)
96 #define attach_log_verbose(attach, origin, ...) \
97  attach_log_level_fmt(attach, LOG_LEVEL_VERBOSE, origin, __VA_ARGS__)
98 #define attach_log_info(attach, origin, ...) \
99  attach_log_level_fmt(attach, LOG_LEVEL_INFO, origin, __VA_ARGS__)
100 #define attach_log_warn(attach, origin, ...) \
101  attach_log_level_fmt(attach, LOG_LEVEL_WARNING, origin, __VA_ARGS__)
102 #define attach_log_error(attach, origin, ...) \
103  attach_log_level_fmt(attach, LOG_LEVEL_ERROR, origin, __VA_ARGS__)
104 #define attach_log_fatal(attach, origin, ...) \
105  attach_log_level_fmt(attach, LOG_LEVEL_FATAL, origin, __VA_ARGS__)
106 #define attach_log_enter(attach, origin, ...) \
107  attach_log_level_fmt(attach, LOG_LEVEL_ENTER, origin, __VA_ARGS__)
108 #define attach_log_leave(attach, origin, ...) \
109  attach_log_level_fmt(attach, LOG_LEVEL_LEAVE, origin, __VA_ARGS__)
110 
111 #define log_extra(origin, ...) log_level_fmt(LOG_LEVEL_EXTRADEBUG, origin, __VA_ARGS__)
112 #define log_debug(origin, ...) log_level_fmt(LOG_LEVEL_DEBUG, origin, __VA_ARGS__)
113 #define log_verbose(origin, ...) log_level_fmt(LOG_LEVEL_VERBOSE, origin, __VA_ARGS__)
114 #define log_info(origin, ...) log_level_fmt(LOG_LEVEL_INFO, origin, __VA_ARGS__)
115 #define log_warn(origin, ...) log_level_fmt(LOG_LEVEL_WARNING, origin, __VA_ARGS__)
116 #define log_error(origin, ...) log_level_fmt(LOG_LEVEL_ERROR, origin, __VA_ARGS__)
117 #define log_fatal(origin, ...) log_level_fmt(LOG_LEVEL_FATAL, origin, __VA_ARGS__)
118 #define log_enter(origin, ...) log_level_fmt(LOG_LEVEL_ENTER, origin, __VA_ARGS__)
119 #define log_leave(origin, ...) log_level_fmt(LOG_LEVEL_LEAVE, origin, __VA_ARGS__)
120 #define log_separator(origin) log_level(LOG_LEVEL_SEPARATOR, origin, NULL)
121 #define log_check(origin, id) log_level(LOG_LEVEL_CHECKPOINT, origin, id)
122 
134 #ifndef LOG_ORIGIN
135 # define LOG_ORIGIN __FILE__
136 #endif
137 
140 #define attach_extra(attach, ...) \
141  attach_log_extra(attach, LOG_ORIGIN, __VA_ARGS__)
142 #define attach_debug(attach, ...) \
143  attach_log_debug(attach, LOG_ORIGIN, __VA_ARGS__)
144 #define attach_verbose(attach, ...) \
145  attach_log_verbose(attach, LOG_ORIGIN, __VA_ARGS__)
146 #define attach_info(attach, ...) \
147  attach_log_info(attach, LOG_ORIGIN, __VA_ARGS__)
148 #define attach_warn(attach, ...) \
149  attach_log_warn(attach, LOG_ORIGIN, __VA_ARGS__)
150 #define attach_error(attach, ...) \
151  attach_log_error(attach, LOG_ORIGIN, __VA_ARGS__)
152 #define attach_fatal(attach, ...) \
153  attach_log_fatal(attach, LOG_ORIGIN, __VA_ARGS__)
154 #define attach_enter(attach, ...) \
155  attach_log_enter(attach, LOG_ORIGIN, __VA_ARGS__)
156 #define attach_leave(attach, ...) \
157  attach_log_leave(attach, LOG_ORIGIN, __VA_ARGS__)
158 #define attach_check(attach, id) \
159  attach_log_check(attach, LOG_ORIGIN, id)
160 
161 // (You can define LOG_NOSTUBS to avoid having these stubs/shortcuts.
162 // This might be useful in case of ambiguities or name collisions.)
163 #ifndef LOG_NOSTUBS
164  #define extra(...) log_extra(LOG_ORIGIN, __VA_ARGS__)
165  #define debug(...) log_debug(LOG_ORIGIN, __VA_ARGS__)
166  #define verbose(...) log_verbose(LOG_ORIGIN, __VA_ARGS__)
167  #define info(...) log_info(LOG_ORIGIN, __VA_ARGS__)
168  #define warn(...) log_warn(LOG_ORIGIN, __VA_ARGS__)
169  #define error(...) log_error(LOG_ORIGIN, __VA_ARGS__)
170  #define fatal(...) log_fatal(LOG_ORIGIN, __VA_ARGS__)
171  #define enter(...) log_enter(LOG_ORIGIN, __VA_ARGS__)
172  #define leave(...) log_leave(LOG_ORIGIN, __VA_ARGS__)
173  #define separator() log_separator(LOG_ORIGIN)
174  #define check(id) log_check(LOG_ORIGIN, id)
175  #define scratch(key, value) log_scratch(LOG_ORIGIN, key, value)
176 #endif
177 
179 #endif // LOG_H
enter scope (e.g. function) / increase nesting level
Definition: log.h:19
void attach_log_level_ap(msgpack_object *attachment, LOG_LEVEL level, const char *origin, const char *fmt, va_list ap)
printf-style creation of a log message with attachment, using format string and a vararg list...
Definition: log.c:333
"standard" (informational) log messages
Definition: log.h:15
void log_register_backend(backend_callback_t *callback, backend_command_t *notify, void *userptr)
Add a callback function to the list of logging backends.
Definition: log.c:102
may be used (if implemented) to show a separator
Definition: log.h:23
void log_unregister_backend(backend_callback_t *callback, void *userptr)
Remove a callback function from the list of logging backends.
Definition: log.c:123
void * userptr
arbitrary "user" data.
Definition: log.h:48
debugging log level
Definition: log.h:13
check point, shows ID and an automatic pass count
Definition: log.h:25
void attach_log_level_fmt(msgpack_object *attachment, LOG_LEVEL level, const char *origin, const char *fmt,...)
vararg wrapper for attach_log_level_ap()
Definition: log.c:343
fatal error (might terminate execution)
Definition: log.h:18
backend_callback_t * callback
callback function to process a log message
Definition: log.h:43
leave scope (e.g. function) / decrease nesting level
Definition: log.h:20
LOG_NOTIFY
(internal) logging backend notifications
Definition: log.h:30
LOG_LEVEL
logging levels ("verbosity")
Definition: log.h:11
may be used (if implemented) to resume logging output
Definition: log.h:22
an entry in the list of logging backends
Definition: log.h:42
warning
Definition: log.h:16
arbitrary key-value pairs, presented in a viewer-specific way
Definition: log.h:26
backend_command_t * notify
callback function for backend notifications
Definition: log.h:44
void backend_callback_t(msgpack_sbuffer *logmsg, LOG_LEVEL level, void *userptr)
prototype for a logging backend callback function
Definition: log.h:36
void log_reset(bool with_checkpoints)
Reset (internal) log system variables.
Definition: log.c:162
void log_scratch(const char *origin, const char *key, const char *value)
"scratchpad" message logging a key-value pair
Definition: log.c:355
void log_shutdown(void)
Notify all the logging backends of impending shutdown.
Definition: log.c:145
"extra" debugging (more verbose than LOG_LEVEL_DEBUG)
Definition: log.h:12
verbose, more output than LOG_LEVEL_INFO
Definition: log.h:14
error
Definition: log.h:17
boolean data type and constants/macros
notify backends to apply new logging/verbosity level
Definition: log.h:31
const char * log_level_string(LOG_LEVEL level)
return string representation of a LOG_LEVEL
Definition: log.c:363
void backend_command_t(LOG_NOTIFY reason, void *userptr)
prototype for a logging backend "command"/notification function
Definition: log.h:38
may be used (if implemented) to clear a backlog / console
Definition: log.h:24
inform backends on removal, or log system shutdown
Definition: log.h:32
void attach_log_level(msgpack_object *attachment, LOG_LEVEL level, const char *origin, const char *msg, int len)
Create a simple log message with an attachment.
Definition: log.c:297
may be used (if implemented) to pause logging output
Definition: log.h:21