From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LBFVn-0007e4-Bh for qemu-devel@nongnu.org; Fri, 12 Dec 2008 16:25:27 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LBFVm-0007dX-Bd for qemu-devel@nongnu.org; Fri, 12 Dec 2008 16:25:26 -0500 Received: from [199.232.76.173] (port=45300 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LBFVl-0007dK-Ut for qemu-devel@nongnu.org; Fri, 12 Dec 2008 16:25:25 -0500 Received: from mx2.redhat.com ([66.187.237.31]:33584) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LBFVl-00009C-Bd for qemu-devel@nongnu.org; Fri, 12 Dec 2008 16:25:25 -0500 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id mBCLPMpG005854 for ; Fri, 12 Dec 2008 16:25:24 -0500 From: Eduardo Habkost Date: Fri, 12 Dec 2008 19:24:19 -0200 Message-Id: <1229117060-8467-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1229117060-8467-1-git-send-email-ehabkost@redhat.com> References: <1229117060-8467-1-git-send-email-ehabkost@redhat.com> Subject: [Qemu-devel] [RFC PATCH 1/2] Create macros that will help define the logging API Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Eduardo Habkost These macros are _not_ a proposal for a definitive new logging API. They are just a step for it: a way to group all usage patterns of the logfile/loglevel variables on a single place. Signed-off-by: Eduardo Habkost --- qemu-log.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 86 insertions(+), 0 deletions(-) diff --git a/qemu-log.h b/qemu-log.h index 1ebea81..fccfb11 100644 --- a/qemu-log.h +++ b/qemu-log.h @@ -1,7 +1,93 @@ #ifndef QEMU_LOG_H #define QEMU_LOG_H +/* The deprecated global variables: */ extern FILE *logfile; extern int loglevel; + +/* + * The new API: + * + */ + +/* Log settings checking macros: */ + +/* Returns true if qemu_log() will really write somewhere + */ +#define qemu_log_enabled() (logfile != NULL) + +/* Returns true if a bit is set in the current loglevel mask + */ +#define qemu_loglevel_mask(b) ((loglevel & (b)) != 0) + + +/* Logging functions: */ + +/* main logging function + */ +#define qemu_log(...) do { \ + if (logfile) \ + fprintf(logfile, ## __VA_ARGS__); \ + } while (0) + +/* vfprintf-like logging function + */ +#define qemu_log_vprintf(fmt, va) do { \ + if (logfile) \ + vfprintf(logfile, fmt, va); \ + } while (0) + +/* log only if a bit is set on the current loglevel mask + */ +#define qemu_log_mask(b, ...) do { \ + if (loglevel & (b)) \ + fprintf(logfile, ## __VA_ARGS__); \ + } while (0) + + + + +/* Special cases: */ + +/* cpu_dump_state() logging functions: */ +#define log_cpu_state(env, f) cpu_dump_state((env), logfile, fprintf, (f)); +#define log_cpu_state_mask(b, env, f) do { \ + if (loglevel & (b)) log_cpu_state((env), (f)); \ + } while (0) + +/* disas() and target_disas() to logfile: */ +#define log_target_disas(start, len, flags) \ + target_disas(logfile, (start), (len), (flags)) +#define log_disas(start, len) \ + disas(logfile, (start), (len)) + +/* page_dump() output to the log file: */ +#define log_page_dump() page_dump(logfile) + + + +/* Maintenance: */ + +/* fflush() the log file */ +#define qemu_log_flush() fflush(logfile) + +/* Close the log file */ +#define qemu_log_close() do { \ + fclose(logfile); \ + logfile = NULL; \ + } while (0) + +/* Set up a new log file */ +#define qemu_log_set_file(f) do { \ + logfile = (f); \ + } while (0) + +/* Set up a new log file, only if none is set */ +#define qemu_log_try_set_file(f) do { \ + if (!logfile) \ + logfile = (f); \ + } while (0) + + #endif -- 1.5.5.GIT