qemu-iotests: Some backing file COW tests
[qemu.git] / qemu-log.h
bloba9b3ca4e0b3c5047d3ddb63ba2e970edc2dba607
1 #ifndef QEMU_LOG_H
2 #define QEMU_LOG_H
4 /* The deprecated global variables: */
5 extern FILE *logfile;
6 extern int loglevel;
9 /*
10 * The new API:
14 /* Log settings checking macros: */
16 /* Returns true if qemu_log() will really write somewhere
18 #define qemu_log_enabled() (logfile != NULL)
20 /* Returns true if a bit is set in the current loglevel mask
22 #define qemu_loglevel_mask(b) ((loglevel & (b)) != 0)
25 /* Logging functions: */
27 /* main logging function
29 #define qemu_log(...) do { \
30 if (logfile) \
31 fprintf(logfile, ## __VA_ARGS__); \
32 } while (0)
34 /* vfprintf-like logging function
36 #define qemu_log_vprintf(fmt, va) do { \
37 if (logfile) \
38 vfprintf(logfile, fmt, va); \
39 } while (0)
41 /* log only if a bit is set on the current loglevel mask
43 #define qemu_log_mask(b, ...) do { \
44 if (loglevel & (b)) \
45 fprintf(logfile, ## __VA_ARGS__); \
46 } while (0)
51 /* Special cases: */
53 #ifdef NEED_CPU_H
54 /* cpu_dump_state() logging functions: */
55 #define log_cpu_state(env, f) cpu_dump_state((env), logfile, fprintf, (f));
56 #define log_cpu_state_mask(b, env, f) do { \
57 if (loglevel & (b)) log_cpu_state((env), (f)); \
58 } while (0)
60 /* disas() and target_disas() to logfile: */
61 #define log_target_disas(start, len, flags) \
62 target_disas(logfile, (start), (len), (flags))
63 #define log_disas(start, len) \
64 disas(logfile, (start), (len))
66 /* page_dump() output to the log file: */
67 #define log_page_dump() page_dump(logfile)
68 #endif
72 /* Maintenance: */
74 /* fflush() the log file */
75 #define qemu_log_flush() fflush(logfile)
77 /* Close the log file */
78 #define qemu_log_close() do { \
79 fclose(logfile); \
80 logfile = NULL; \
81 } while (0)
83 /* Set up a new log file */
84 #define qemu_log_set_file(f) do { \
85 logfile = (f); \
86 } while (0)
88 /* Set up a new log file, only if none is set */
89 #define qemu_log_try_set_file(f) do { \
90 if (!logfile) \
91 logfile = (f); \
92 } while (0)
95 #endif