From: Eduardo Habkost <ehabkost@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: qemu-devel@nongnu.org, Eduardo Habkost <ehabkost@redhat.com>
Subject: [Qemu-devel] [PATCH 2/5] Define macros that will become the new logging API
Date: Tue, 13 Jan 2009 20:42:30 -0200 [thread overview]
Message-ID: <1231886553-4728-3-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1231886553-4728-1-git-send-email-ehabkost@redhat.com>
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 <ehabkost@redhat.com>
---
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.6.rc3.11.g5f54d
next prev parent reply other threads:[~2009-01-13 22:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-13 22:42 [Qemu-devel] [PATCH 0/5] Logging cleanup, take 3 Eduardo Habkost
2009-01-13 22:42 ` [Qemu-devel] [PATCH 1/5] Clean up debugging code #ifdefs Eduardo Habkost
2009-01-13 22:42 ` Eduardo Habkost [this message]
2009-01-13 22:42 ` [Qemu-devel] [PATCH 3/5] Convert references to logfile/loglevel to use qemu_log*() macros Eduardo Habkost
2009-01-15 21:53 ` [Qemu-devel] " Anthony Liguori
2009-01-15 22:29 ` Eduardo Habkost
2009-01-13 22:42 ` [Qemu-devel] [PATCH 4/5] global s/fflush(logfile)/qemu_log_flush()/ Eduardo Habkost
2009-01-13 22:42 ` [Qemu-devel] [PATCH 5/5] global s/loglevel & X/qemu_loglevel_mask(X)/ Eduardo Habkost
2009-01-15 22:37 ` [Qemu-devel] " Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1231886553-4728-3-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).