root / qemu-log.h @ 9ea37780
History | View | Annotate | Download (2.1 kB)
1 | 79383c9c | blueswir1 | #ifndef QEMU_LOG_H
|
---|---|---|---|
2 | 79383c9c | blueswir1 | #define QEMU_LOG_H
|
3 | 79383c9c | blueswir1 | |
4 | 6d2c5146 | aliguori | /* The deprecated global variables: */
|
5 | 79383c9c | blueswir1 | extern FILE *logfile;
|
6 | 79383c9c | blueswir1 | extern int loglevel; |
7 | 79383c9c | blueswir1 | |
8 | 6d2c5146 | aliguori | |
9 | 6d2c5146 | aliguori | /*
|
10 | 6d2c5146 | aliguori | * The new API:
|
11 | 6d2c5146 | aliguori | *
|
12 | 6d2c5146 | aliguori | */
|
13 | 6d2c5146 | aliguori | |
14 | 6d2c5146 | aliguori | /* Log settings checking macros: */
|
15 | 6d2c5146 | aliguori | |
16 | 6d2c5146 | aliguori | /* Returns true if qemu_log() will really write somewhere
|
17 | 6d2c5146 | aliguori | */
|
18 | 6d2c5146 | aliguori | #define qemu_log_enabled() (logfile != NULL) |
19 | 6d2c5146 | aliguori | |
20 | 6d2c5146 | aliguori | /* Returns true if a bit is set in the current loglevel mask
|
21 | 6d2c5146 | aliguori | */
|
22 | 6d2c5146 | aliguori | #define qemu_loglevel_mask(b) ((loglevel & (b)) != 0) |
23 | 6d2c5146 | aliguori | |
24 | 6d2c5146 | aliguori | |
25 | 6d2c5146 | aliguori | /* Logging functions: */
|
26 | 6d2c5146 | aliguori | |
27 | 6d2c5146 | aliguori | /* main logging function
|
28 | 6d2c5146 | aliguori | */
|
29 | 6d2c5146 | aliguori | #define qemu_log(...) do { \ |
30 | 6d2c5146 | aliguori | if (logfile) \
|
31 | 6d2c5146 | aliguori | fprintf(logfile, ## __VA_ARGS__); \ |
32 | 6d2c5146 | aliguori | } while (0) |
33 | 6d2c5146 | aliguori | |
34 | 6d2c5146 | aliguori | /* vfprintf-like logging function
|
35 | 6d2c5146 | aliguori | */
|
36 | 6d2c5146 | aliguori | #define qemu_log_vprintf(fmt, va) do { \ |
37 | 6d2c5146 | aliguori | if (logfile) \
|
38 | 6d2c5146 | aliguori | vfprintf(logfile, fmt, va); \ |
39 | 6d2c5146 | aliguori | } while (0) |
40 | 6d2c5146 | aliguori | |
41 | 6d2c5146 | aliguori | /* log only if a bit is set on the current loglevel mask
|
42 | 6d2c5146 | aliguori | */
|
43 | 6d2c5146 | aliguori | #define qemu_log_mask(b, ...) do { \ |
44 | 6d2c5146 | aliguori | if (loglevel & (b)) \
|
45 | 6d2c5146 | aliguori | fprintf(logfile, ## __VA_ARGS__); \ |
46 | 6d2c5146 | aliguori | } while (0) |
47 | 6d2c5146 | aliguori | |
48 | 6d2c5146 | aliguori | |
49 | 6d2c5146 | aliguori | |
50 | 6d2c5146 | aliguori | |
51 | 6d2c5146 | aliguori | /* Special cases: */
|
52 | 6d2c5146 | aliguori | |
53 | 6d2c5146 | aliguori | /* cpu_dump_state() logging functions: */
|
54 | 6d2c5146 | aliguori | #define log_cpu_state(env, f) cpu_dump_state((env), logfile, fprintf, (f));
|
55 | 6d2c5146 | aliguori | #define log_cpu_state_mask(b, env, f) do { \ |
56 | 6d2c5146 | aliguori | if (loglevel & (b)) log_cpu_state((env), (f)); \
|
57 | 6d2c5146 | aliguori | } while (0) |
58 | 6d2c5146 | aliguori | |
59 | 6d2c5146 | aliguori | /* disas() and target_disas() to logfile: */
|
60 | 6d2c5146 | aliguori | #define log_target_disas(start, len, flags) \
|
61 | 6d2c5146 | aliguori | target_disas(logfile, (start), (len), (flags)) |
62 | 6d2c5146 | aliguori | #define log_disas(start, len) \
|
63 | 6d2c5146 | aliguori | disas(logfile, (start), (len)) |
64 | 6d2c5146 | aliguori | |
65 | 6d2c5146 | aliguori | /* page_dump() output to the log file: */
|
66 | 6d2c5146 | aliguori | #define log_page_dump() page_dump(logfile)
|
67 | 6d2c5146 | aliguori | |
68 | 6d2c5146 | aliguori | |
69 | 6d2c5146 | aliguori | |
70 | 6d2c5146 | aliguori | /* Maintenance: */
|
71 | 6d2c5146 | aliguori | |
72 | 6d2c5146 | aliguori | /* fflush() the log file */
|
73 | 6d2c5146 | aliguori | #define qemu_log_flush() fflush(logfile)
|
74 | 6d2c5146 | aliguori | |
75 | 6d2c5146 | aliguori | /* Close the log file */
|
76 | 6d2c5146 | aliguori | #define qemu_log_close() do { \ |
77 | 6d2c5146 | aliguori | fclose(logfile); \ |
78 | 6d2c5146 | aliguori | logfile = NULL; \
|
79 | 6d2c5146 | aliguori | } while (0) |
80 | 6d2c5146 | aliguori | |
81 | 6d2c5146 | aliguori | /* Set up a new log file */
|
82 | 6d2c5146 | aliguori | #define qemu_log_set_file(f) do { \ |
83 | 6d2c5146 | aliguori | logfile = (f); \ |
84 | 6d2c5146 | aliguori | } while (0) |
85 | 6d2c5146 | aliguori | |
86 | 6d2c5146 | aliguori | /* Set up a new log file, only if none is set */
|
87 | 6d2c5146 | aliguori | #define qemu_log_try_set_file(f) do { \ |
88 | 6d2c5146 | aliguori | if (!logfile) \
|
89 | 6d2c5146 | aliguori | logfile = (f); \ |
90 | 6d2c5146 | aliguori | } while (0) |
91 | 6d2c5146 | aliguori | |
92 | 6d2c5146 | aliguori | |
93 | 79383c9c | blueswir1 | #endif |