log: do not unnecessarily include qom/cpu.h
[qemu.git] / include / qemu / log.h
blob09722e3c6c394b5d238a4dd1622e403162fb4bf7
1 #ifndef QEMU_LOG_H
2 #define QEMU_LOG_H
4 #include <stdarg.h>
5 #include <stdbool.h>
6 #include <stdio.h>
7 #include "qemu/compiler.h"
9 /* Private global variables, don't use */
10 extern FILE *qemu_logfile;
11 extern int qemu_loglevel;
13 /*
14 * The new API:
18 /* Log settings checking macros: */
20 /* Returns true if qemu_log() will really write somewhere
22 static inline bool qemu_log_enabled(void)
24 return qemu_logfile != NULL;
27 /* Returns true if qemu_log() will write somewhere else than stderr
29 static inline bool qemu_log_separate(void)
31 return qemu_logfile != NULL && qemu_logfile != stderr;
34 #define CPU_LOG_TB_OUT_ASM (1 << 0)
35 #define CPU_LOG_TB_IN_ASM (1 << 1)
36 #define CPU_LOG_TB_OP (1 << 2)
37 #define CPU_LOG_TB_OP_OPT (1 << 3)
38 #define CPU_LOG_INT (1 << 4)
39 #define CPU_LOG_EXEC (1 << 5)
40 #define CPU_LOG_PCALL (1 << 6)
41 #define CPU_LOG_TB_CPU (1 << 8)
42 #define CPU_LOG_RESET (1 << 9)
43 #define LOG_UNIMP (1 << 10)
44 #define LOG_GUEST_ERROR (1 << 11)
45 #define CPU_LOG_MMU (1 << 12)
46 #define CPU_LOG_TB_NOCHAIN (1 << 13)
47 #define CPU_LOG_PAGE (1 << 14)
49 /* Returns true if a bit is set in the current loglevel mask
51 static inline bool qemu_loglevel_mask(int mask)
53 return (qemu_loglevel & mask) != 0;
56 /* Logging functions: */
58 /* main logging function
60 void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
62 /* vfprintf-like logging function
64 static inline void GCC_FMT_ATTR(1, 0)
65 qemu_log_vprintf(const char *fmt, va_list va)
67 if (qemu_logfile) {
68 vfprintf(qemu_logfile, fmt, va);
72 /* log only if a bit is set on the current loglevel mask
74 void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
77 /* Maintenance: */
79 /* fflush() the log file */
80 static inline void qemu_log_flush(void)
82 fflush(qemu_logfile);
85 /* Close the log file */
86 static inline void qemu_log_close(void)
88 if (qemu_logfile) {
89 if (qemu_logfile != stderr) {
90 fclose(qemu_logfile);
92 qemu_logfile = NULL;
96 /* Set up a new log file */
97 static inline void qemu_log_set_file(FILE *f)
99 qemu_logfile = f;
102 /* define log items */
103 typedef struct QEMULogItem {
104 int mask;
105 const char *name;
106 const char *help;
107 } QEMULogItem;
109 extern const QEMULogItem qemu_log_items[];
111 /* This is the function that actually does the work of
112 * changing the log level; it should only be accessed via
113 * the qemu_set_log() wrapper.
115 void do_qemu_set_log(int log_flags, bool use_own_buffers);
117 static inline void qemu_set_log(int log_flags)
119 #ifdef CONFIG_USER_ONLY
120 do_qemu_set_log(log_flags, true);
121 #else
122 do_qemu_set_log(log_flags, false);
123 #endif
126 void qemu_set_log_filename(const char *filename);
127 int qemu_str_to_log_mask(const char *str);
129 /* Print a usage message listing all the valid logging categories
130 * to the specified FILE*.
132 void qemu_print_log_usage(FILE *f);
134 #endif