]> Git Repo - qemu.git/blob - include/qemu/log.h
trace: convert stderr backend to log
[qemu.git] / include / qemu / log.h
1 #ifndef QEMU_LOG_H
2 #define QEMU_LOG_H
3
4 #include <stdarg.h>
5 #include <stdbool.h>
6 #include <stdio.h>
7 #include "qemu/compiler.h"
8
9 /* Private global variables, don't use */
10 extern FILE *qemu_logfile;
11 extern int qemu_loglevel;
12
13 /* 
14  * The new API:
15  *
16  */
17
18 /* Log settings checking macros: */
19
20 /* Returns true if qemu_log() will really write somewhere
21  */
22 static inline bool qemu_log_enabled(void)
23 {
24     return qemu_logfile != NULL;
25 }
26
27 /* Returns true if qemu_log() will write somewhere else than stderr
28  */
29 static inline bool qemu_log_separate(void)
30 {
31     return qemu_logfile != NULL && qemu_logfile != stderr;
32 }
33
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)
48 #define LOG_TRACE          (1 << 15)
49
50 /* Returns true if a bit is set in the current loglevel mask
51  */
52 static inline bool qemu_loglevel_mask(int mask)
53 {
54     return (qemu_loglevel & mask) != 0;
55 }
56
57 /* Logging functions: */
58
59 /* main logging function
60  */
61 void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
62
63 /* vfprintf-like logging function
64  */
65 static inline void GCC_FMT_ATTR(1, 0)
66 qemu_log_vprintf(const char *fmt, va_list va)
67 {
68     if (qemu_logfile) {
69         vfprintf(qemu_logfile, fmt, va);
70     }
71 }
72
73 /* log only if a bit is set on the current loglevel mask
74  */
75 void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
76
77
78 /* Maintenance: */
79
80 /* fflush() the log file */
81 static inline void qemu_log_flush(void)
82 {
83     fflush(qemu_logfile);
84 }
85
86 /* Close the log file */
87 static inline void qemu_log_close(void)
88 {
89     if (qemu_logfile) {
90         if (qemu_logfile != stderr) {
91             fclose(qemu_logfile);
92         }
93         qemu_logfile = NULL;
94     }
95 }
96
97 /* Set up a new log file */
98 static inline void qemu_log_set_file(FILE *f)
99 {
100     qemu_logfile = f;
101 }
102
103 /* define log items */
104 typedef struct QEMULogItem {
105     int mask;
106     const char *name;
107     const char *help;
108 } QEMULogItem;
109
110 extern const QEMULogItem qemu_log_items[];
111
112 /* This is the function that actually does the work of
113  * changing the log level; it should only be accessed via
114  * the qemu_set_log() wrapper.
115  */
116 void do_qemu_set_log(int log_flags, bool use_own_buffers);
117
118 static inline void qemu_set_log(int log_flags)
119 {
120 #ifdef CONFIG_USER_ONLY
121     do_qemu_set_log(log_flags, true);
122 #else
123     do_qemu_set_log(log_flags, false);
124 #endif
125 }
126
127 void qemu_set_log_filename(const char *filename);
128 int qemu_str_to_log_mask(const char *str);
129
130 /* Print a usage message listing all the valid logging categories
131  * to the specified FILE*.
132  */
133 void qemu_print_log_usage(FILE *f);
134
135 #endif
This page took 0.031594 seconds and 4 git commands to generate.