-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.h
63 lines (54 loc) · 1.3 KB
/
error.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
58
59
60
61
62
63
/* SimAK65 debug
* Copyright A.K. 2018, 2023
*/
#ifndef SIMAK65_ERROR_H_
#define SIMAK65_ERROR_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#ifndef LOG_LEVEL
#define LOG_LEVEL 3
#endif
#define RED "\x1B[31m"
#define GRN "\x1B[32m"
#define YEL "\x1B[33m"
#define RESET "\x1B[0m"
#if LOG_LEVEL >= 1
#define FATAL(msg, ...) do { \
fprintf(stderr, RED "[FATAL] [%s:%d] (%s): ", __FILE__, __LINE__, __func__); \
fprintf(stderr, msg, ##__VA_ARGS__); \
fprintf(stderr, "\nPress Any Key to Exit...\n" RESET); \
getchar(); \
exit(1); \
} while (0)
#else
#define FATAL(msg, ...)
#endif
#if LOG_LEVEL >= 2
#define WARN(msg, ...) do { \
fprintf(stderr, YEL "[WARNING] [%s:%d] (%s): ", __FILE__, __LINE__, __func__); \
fprintf(stderr, msg, ##__VA_ARGS__); \
fprintf(stderr, "\n" RESET); \
} while (0)
#else
#define WARN(msg, ...)
#endif
#if LOG_LEVEL >= 3
#define INFO(msg, ...) do { \
printf("[INFO] "); \
printf(msg, ##__VA_ARGS__); \
printf("\n"); \
} while (0)
#else
#define INFO(msg, ...)
#endif
#if LOG_LEVEL >= 4
#define DEBUG(msg, ...) do { \
fprintf(stderr, GRN "[DEBUG] [%s:%d] (%s): ", __FILE__, __LINE__, __func__); \
fprintf(stderr, msg, ##__VA_ARGS__); \
fprintf(stderr, "\n" RESET); \
} while (0)
#else
#define DEBUG(msg, ...)
#endif
#endif /* SIMAK65_ERROR_H_ */