libPeConv
A library to load, manipulate, dump PE files.
Loading...
Searching...
No Matches
libpeconv
include
peconv
logger.h
Go to the documentation of this file.
1
#pragma once
2
#include <stdio.h>
3
4
// Verbosity levels
5
#define LOG_LEVEL_NONE 0
// silent
6
#define LOG_LEVEL_ERROR 1
// something broke
7
#define LOG_LEVEL_WARNING 2
// something looks wrong
8
#define LOG_LEVEL_INFO 3
// notable operational events
9
#define LOG_LEVEL_DEBUG 4
// detailed tracing, noisy
10
11
#ifndef LOG_VERBOSITY
12
# define LOG_VERBOSITY LOG_LEVEL_ERROR
13
#endif
14
15
// Output sink selection
16
#ifdef LOG_USE_DEBUGOUT
17
# include <windows.h>
18
# include <stdio.h>
19
// Format into a local buffer, then hand off to OutputDebugStringA
20
# define _LOG(tag, fmt, ...) \
21
do { \
22
char _log_buf[512]; \
23
snprintf(_log_buf, sizeof(_log_buf), \
24
"[" tag "] %s:%d: " fmt "\n", \
25
__FILE__, __LINE__, ##__VA_ARGS__); \
26
OutputDebugStringA(_log_buf); \
27
} while(0)
28
#else
29
# define _LOG(tag, fmt, ...) \
30
fprintf(stderr, "[" tag "] %s:%d: " fmt "\n", \
31
__FILE__, __LINE__, ##__VA_ARGS__)
32
#endif
33
34
// Public macros
35
#if LOG_VERBOSITY >= LOG_LEVEL_ERROR
36
# define LOG_ERROR(fmt, ...) _LOG("ERROR", fmt, ##__VA_ARGS__)
37
#else
38
# define LOG_ERROR(fmt, ...) do {} while(0)
39
#endif
40
41
#if LOG_VERBOSITY >= LOG_LEVEL_WARNING
42
# define LOG_WARNING(fmt, ...) _LOG("WARNING", fmt, ##__VA_ARGS__)
43
#else
44
# define LOG_WARNING(fmt, ...) do {} while(0)
45
#endif
46
47
#if LOG_VERBOSITY >= LOG_LEVEL_INFO
48
# define LOG_INFO(fmt, ...) _LOG("INFO", fmt, ##__VA_ARGS__)
49
#else
50
# define LOG_INFO(fmt, ...) do {} while(0)
51
#endif
52
53
#if LOG_VERBOSITY >= LOG_LEVEL_DEBUG
54
# define LOG_DEBUG(fmt, ...) _LOG("DEBUG", fmt, ##__VA_ARGS__)
55
#else
56
# define LOG_DEBUG(fmt, ...) do {} while(0)
57
#endif
Generated on
for libPeConv by
1.16.1