Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LNa8N-00036h-4Z for qemu-devel@nongnu.org; Thu, 15 Jan 2009 16:52:15 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LNa8L-00033f-7X for qemu-devel@nongnu.org; Thu, 15 Jan 2009 16:52:14 -0500 Received: from [199.232.76.173] (port=38322 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LNa8K-000338-UJ for qemu-devel@nongnu.org; Thu, 15 Jan 2009 16:52:12 -0500 Received: from savannah.gnu.org ([199.232.41.3]:50608 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LNa8K-0001eX-H0 for qemu-devel@nongnu.org; Thu, 15 Jan 2009 16:52:12 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LNa8J-00005n-U4 for qemu-devel@nongnu.org; Thu, 15 Jan 2009 21:52:12 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LNa8J-00005i-KX for qemu-devel@nongnu.org; Thu, 15 Jan 2009 21:52:11 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 15 Jan 2009 21:52:11 +0000 Subject: [Qemu-devel] [6333] Define macros that will become the new logging API (Eduardo Habkost) 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 Revision: 6333 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6333 Author: aliguori Date: 2009-01-15 21:52:11 +0000 (Thu, 15 Jan 2009) Log Message: ----------- Define macros that will become the new logging API (Eduardo Habkost) These macros are NOT a proposal for a definitive new logging API. They are just a step for it: a way to mark all usage patterns of the logfile/loglevel variables on a single place. Signed-off-by: Eduardo Habkost Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/qemu-log.h Modified: trunk/qemu-log.h =================================================================== --- trunk/qemu-log.h 2009-01-15 21:48:06 UTC (rev 6332) +++ trunk/qemu-log.h 2009-01-15 21:52:11 UTC (rev 6333) @@ -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