forked from synacktiv/CVE-2021-1782
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.h
57 lines (51 loc) · 1.95 KB
/
log.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* log.h
* Brandon Azad
*/
#ifndef VOUCHER_SWAP__LOG_H_
#define VOUCHER_SWAP__LOG_H_
#include <stdarg.h>
#include <stdio.h>
/*
* log_implementation
*
* Description:
* This is the log handler that will be executed when code wants to log a message. The default
* implementation logs the message to stderr. Setting this value to NULL will disable all
* logging. Specify a custom log handler to process log messages in another way.
*
* Parameters:
* type A character representing the type of message that is being
* logged.
* format A printf-style format string describing the error message.
* ap The variadic argument list for the format string.
*
* Log Type:
* The type parameter is one of:
* - D: Debug: Used for debugging messages. Set the DEBUG build variable to control debug
* verbosity.
* - I: Info: Used to convey general information about the exploit or its progress.
* - W: Warning: Used to indicate that an unusual but possibly recoverable condition was
* encountered.
* - E: Error: Used to indicate that an unrecoverable error was encountered. The code
* might continue running after an error was encountered, but it probably will
* not succeed.
*/
extern void (*log_implementation)(char type, const char *format, va_list ap);
#define DEBUG_LEVEL(level) (DEBUG && level <= DEBUG)
#if DEBUG
#define DEBUG_TRACE(level, fmt, ...) \
do { \
if (DEBUG_LEVEL(level)) { \
log_internal('D', fmt, ##__VA_ARGS__); \
} \
} while (0)
#else
#define DEBUG_TRACE(level, fmt, ...) do {} while (0)
#endif
#define INFO(fmt, ...) log_internal('I', fmt, ##__VA_ARGS__)
#define WARNING(fmt, ...) log_internal('W', fmt, ##__VA_ARGS__)
#define ERROR(fmt, ...) log_internal('E', fmt, ##__VA_ARGS__)
// A function to call the logging implementation.
void log_internal(char type, const char *format, ...) __printflike(2, 3);
#endif