forked from vampirefrog/fathuman
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdis68k_logging.h
More file actions
executable file
·82 lines (71 loc) · 3.95 KB
/
dis68k_logging.h
File metadata and controls
executable file
·82 lines (71 loc) · 3.95 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef __DIS68K_LOGGING_H
#define __DIS68K_LOGGING_H
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "lib/libfat-human68k/ff.h"
#ifndef DIS68K_LOG_STREAM
#define DIS68K_LOG_STREAM stderr
#endif
typedef uint8_t dis68k_verbosity;
#define DIS68K_LEVEL_ERROR 0x01
#define DIS68K_LEVEL_WARN 0x02
#define DIS68K_LEVEL_INFO 0x04
#define DIS68K_LEVEL_DEBUG 0x10
/* FATAL log entries can't be masked, and cause an immediate program
* termination. */
#define DIS68K_LOGF_FATAL(fmt, ...) \
{ \
fprintf(DIS68K_LOG_STREAM, "[FATAL] (%s:%d) " fmt "\n", __FILE__, \
__LINE__, __VA_ARGS__); \
exit(1); \
}
#define DIS68K_LOG_FATAL(msg) DIS68K_LOGF_FATAL("%s", msg)
#define DIS68K_LOGF_ERROR(fmt, ...) \
{ \
extern dis68k_verbosity dis68k_global_loglevel; \
if (dis68k_global_loglevel & DIS68K_LEVEL_ERROR) { \
fprintf(DIS68K_LOG_STREAM, "[ERROR] (%s:%d) " fmt "\n", __FILE__, \
__LINE__, __VA_ARGS__); \
fflush(DIS68K_LOG_STREAM); \
} \
}
#define DIS68K_LOG_ERROR(msg) DIS68K_LOGF_ERROR("%s", msg)
#define DIS68K_LOGF_WARN(fmt, ...) \
{ \
extern dis68k_verbosity dis68k_global_loglevel; \
if (dis68k_global_loglevel & DIS68K_LEVEL_WARN) { \
fprintf(DIS68K_LOG_STREAM, "[WARN] (%s:%d) " fmt "\n", __FILE__, \
__LINE__, __VA_ARGS__); \
fflush(DIS68K_LOG_STREAM); \
} \
}
#define DIS68K_LOG_WARN(msg) DIS68K_LOGF_WARN("%s", msg)
#define DIS68K_LOG_INFO(fmt, ...) \
{ \
extern dis68k_verbosity dis68k_global_loglevel; \
if (dis68k_global_loglevel & DIS68K_LEVEL_INFO) { \
fprintf(DIS68K_LOG_STREAM, "[INFO] (%s:%d) " fmt "\n", __FILE__, \
__LINE__, __VA_ARGS__); \
fflush(DIS68K_LOG_STREAM); \
} \
}
#define DIS68K_LOGF_DEBUG(fmt, ...) \
{ \
extern dis68k_verbosity dis68k_global_loglevel; \
if (dis68k_global_loglevel & DIS68K_LEVEL_DEBUG) { \
fprintf(DIS68K_LOG_STREAM, "[DEBUG] (%s:%-4d) " fmt "\n", __FILE__, \
__LINE__, __VA_ARGS__); \
fflush(DIS68K_LOG_STREAM); \
} \
}
#define DIS68K_LOG_DEBUG(msg) DIS68K_LOGF_DEBUG("%s", msg)
#define DIS68K_ERR_WRAP(fx) \
{ \
FRESULT fr; \
fr = (fx); \
if (fr) { \
DIS68K_LOGF_FATAL("Error %d calling %s: %s", fr, #fx, f_errstr(fr)); \
} \
}
#endif // __DIS68K_LOGGING_H