aboutsummaryrefslogtreecommitdiff
path: root/qemu-log.c
diff options
context:
space:
mode:
authorBlue Swirl <blauwirbel@gmail.com>2012-06-03 16:35:32 +0000
committerBlue Swirl <blauwirbel@gmail.com>2012-06-21 18:45:18 +0000
commiteeacee4d8652d7f3b9224cfe0707c0ed87cc0e96 (patch)
tree124da0ad9aa9593d6e3333ac0f9ef86a377491b6 /qemu-log.c
parent5726c27fa913296aafab9f50b912cea5b3709271 (diff)
qemu-log: cleanup
Don't use global variables directly but via accessor functions. Rename globals. Convert macros to functions, add GCC format attributes. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'qemu-log.c')
-rw-r--r--qemu-log.c54
1 files changed, 38 insertions, 16 deletions
diff --git a/qemu-log.c b/qemu-log.c
index 4d7499fdf5..1dd3de41ad 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -25,17 +25,39 @@ static const char *logfilename = "qemu.log";
#else
static const char *logfilename = "/tmp/qemu.log";
#endif
-FILE *logfile;
-int loglevel;
+FILE *qemu_logfile;
+int qemu_loglevel;
static int log_append = 0;
+void qemu_log(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ if (qemu_logfile) {
+ vfprintf(qemu_logfile, fmt, ap);
+ }
+ va_end(ap);
+}
+
+void qemu_log_mask(int mask, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ if ((qemu_loglevel & mask) && qemu_logfile) {
+ vfprintf(qemu_logfile, fmt, ap);
+ }
+ va_end(ap);
+}
+
/* enable or disable low levels log */
void cpu_set_log(int log_flags)
{
- loglevel = log_flags;
- if (loglevel && !logfile) {
- logfile = fopen(logfilename, log_append ? "a" : "w");
- if (!logfile) {
+ qemu_loglevel = log_flags;
+ if (qemu_loglevel && !qemu_logfile) {
+ qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
+ if (!qemu_logfile) {
perror(logfilename);
_exit(1);
}
@@ -43,30 +65,30 @@ void cpu_set_log(int log_flags)
/* must avoid mmap() usage of glibc by setting a buffer "by hand" */
{
static char logfile_buf[4096];
- setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
+ setvbuf(qemu_logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
}
#elif defined(_WIN32)
/* Win32 doesn't support line-buffering, so use unbuffered output. */
- setvbuf(logfile, NULL, _IONBF, 0);
+ setvbuf(qemu_logfile, NULL, _IONBF, 0);
#else
- setvbuf(logfile, NULL, _IOLBF, 0);
+ setvbuf(qemu_logfile, NULL, _IOLBF, 0);
#endif
log_append = 1;
}
- if (!loglevel && logfile) {
- fclose(logfile);
- logfile = NULL;
+ if (!qemu_loglevel && qemu_logfile) {
+ fclose(qemu_logfile);
+ qemu_logfile = NULL;
}
}
void cpu_set_log_filename(const char *filename)
{
logfilename = strdup(filename);
- if (logfile) {
- fclose(logfile);
- logfile = NULL;
+ if (qemu_logfile) {
+ fclose(qemu_logfile);
+ qemu_logfile = NULL;
}
- cpu_set_log(loglevel);
+ cpu_set_log(qemu_loglevel);
}
const CPULogItem cpu_log_items[] = {