diff options
author | Blue Swirl <blauwirbel@gmail.com> | 2012-06-03 16:35:32 +0000 |
---|---|---|
committer | Blue Swirl <blauwirbel@gmail.com> | 2012-06-21 18:45:18 +0000 |
commit | eeacee4d8652d7f3b9224cfe0707c0ed87cc0e96 (patch) | |
tree | 124da0ad9aa9593d6e3333ac0f9ef86a377491b6 /qemu-log.c | |
parent | 5726c27fa913296aafab9f50b912cea5b3709271 (diff) | |
download | qemu-eeacee4d8652d7f3b9224cfe0707c0ed87cc0e96.zip qemu-eeacee4d8652d7f3b9224cfe0707c0ed87cc0e96.tar.gz qemu-eeacee4d8652d7f3b9224cfe0707c0ed87cc0e96.tar.bz2 |
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.c | 54 |
1 files changed, 38 insertions, 16 deletions
@@ -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[] = { |