qemu-log: move logging to qemu-log.c
[qemu.git] / qemu-log.h
blob34600d6af9147c1798e1111704a7e8729f4823d7
1 #ifndef QEMU_LOG_H
2 #define QEMU_LOG_H
4 /* The deprecated global variables: */
5 extern FILE *logfile;
6 extern int loglevel;
8 /*
9 * The new API:
13 /* Log settings checking macros: */
15 /* Returns true if qemu_log() will really write somewhere
17 #define qemu_log_enabled() (logfile != NULL)
19 #define CPU_LOG_TB_OUT_ASM (1 << 0)
20 #define CPU_LOG_TB_IN_ASM (1 << 1)
21 #define CPU_LOG_TB_OP (1 << 2)
22 #define CPU_LOG_TB_OP_OPT (1 << 3)
23 #define CPU_LOG_INT (1 << 4)
24 #define CPU_LOG_EXEC (1 << 5)
25 #define CPU_LOG_PCALL (1 << 6)
26 #define CPU_LOG_IOPORT (1 << 7)
27 #define CPU_LOG_TB_CPU (1 << 8)
28 #define CPU_LOG_RESET (1 << 9)
30 /* Returns true if a bit is set in the current loglevel mask
32 #define qemu_loglevel_mask(b) ((loglevel & (b)) != 0)
34 /* Logging functions: */
36 /* main logging function
38 #define qemu_log(...) do { \
39 if (logfile) \
40 fprintf(logfile, ## __VA_ARGS__); \
41 } while (0)
43 /* vfprintf-like logging function
45 #define qemu_log_vprintf(fmt, va) do { \
46 if (logfile) \
47 vfprintf(logfile, fmt, va); \
48 } while (0)
50 /* log only if a bit is set on the current loglevel mask
52 #define qemu_log_mask(b, ...) do { \
53 if (loglevel & (b)) \
54 fprintf(logfile, ## __VA_ARGS__); \
55 } while (0)
58 /* Special cases: */
60 #ifdef NEED_CPU_H
61 /* cpu_dump_state() logging functions: */
62 #define log_cpu_state(env, f) cpu_dump_state((env), logfile, fprintf, (f));
63 #define log_cpu_state_mask(b, env, f) do { \
64 if (loglevel & (b)) log_cpu_state((env), (f)); \
65 } while (0)
67 /* disas() and target_disas() to logfile: */
68 #define log_target_disas(start, len, flags) \
69 target_disas(logfile, (start), (len), (flags))
70 #define log_disas(start, len) \
71 disas(logfile, (start), (len))
73 /* page_dump() output to the log file: */
74 #define log_page_dump() page_dump(logfile)
75 #endif
78 /* Maintenance: */
80 /* fflush() the log file */
81 #define qemu_log_flush() fflush(logfile)
83 /* Close the log file */
84 #define qemu_log_close() do { \
85 fclose(logfile); \
86 logfile = NULL; \
87 } while (0)
89 /* Set up a new log file */
90 #define qemu_log_set_file(f) do { \
91 logfile = (f); \
92 } while (0)
94 /* Set up a new log file, only if none is set */
95 #define qemu_log_try_set_file(f) do { \
96 if (!logfile) \
97 logfile = (f); \
98 } while (0)
100 /* define log items */
101 typedef struct CPULogItem {
102 int mask;
103 const char *name;
104 const char *help;
105 } CPULogItem;
107 extern const CPULogItem cpu_log_items[];
109 void cpu_set_log(int log_flags);
110 void cpu_set_log_filename(const char *filename);
111 int cpu_str_to_log_mask(const char *str);
113 #endif