Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Wood <thomas.wood@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH i-g-t v2 1/2] lib: introduce log domains
Date: Wed, 10 Dec 2014 17:24:07 +0000	[thread overview]
Message-ID: <1418232248-25565-1-git-send-email-thomas.wood@intel.com> (raw)
In-Reply-To: <CANkqdn0HxsAVgW7zeLRRFZWNpm+Ocx3k9Tk1-+kq1gzcB5BXqQ@mail.gmail.com>

Log domains can be used to identify the source of log messages, such as
the test being run or the helper library.

v2: Add separate domains for different parts of the helper library and
    use an empty default domain for applications.
    Expand the log output to include the process name and the log level
    of the message in addition to the domain and pid.
    Print the expanded message only for warning and information
    messages.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
---
 lib/Makefile.am |  3 ++-
 lib/igt_core.c  | 28 ++++++++++++++++++++++------
 lib/igt_core.h  | 18 +++++++++++-------
 lib/igt_kms.c   |  2 +-
 4 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/lib/Makefile.am b/lib/Makefile.am
index ab82302..3826a1c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -10,7 +10,8 @@ noinst_HEADERS = check-ndebug.h
 
 AM_CPPFLAGS = -I$(top_srcdir)
 AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS)  \
-	    -DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\"
+	    -DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\" \
+	    -DIGT_LOG_DOMAIN=\""$(subst _,-,$*)"\"
 
 
 LDADD = $(CAIRO_LIBS)
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 13a52a5..b6852dd 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -1429,12 +1429,12 @@ void igt_skip_on_simulation(void)
  * are disabled. "none" completely disables all output and is not recommended
  * since crucial issues only reported at the IGT_LOG_WARN level are ignored.
  */
-void igt_log(enum igt_log_level level, const char *format, ...)
+void igt_log(const char *domain, enum igt_log_level level, const char *format, ...)
 {
 	va_list args;
 
 	va_start(args, format);
-	igt_vlog(level, format, args);
+	igt_vlog(domain, level, format, args);
 	va_end(args);
 }
 
@@ -1451,8 +1451,16 @@ void igt_log(enum igt_log_level level, const char *format, ...)
  * If there is no need to wrap up a vararg list in the caller it is simpler to
  * just use igt_log().
  */
-void igt_vlog(enum igt_log_level level, const char *format, va_list args)
+void igt_vlog(const char *domain, enum igt_log_level level, const char *format, va_list args)
 {
+	FILE *file;
+	const char *igt_log_level_str[] = {
+		"DEBUG",
+		"INFO",
+		"WARNING",
+		"NONE"
+	};
+
 	assert(format);
 
 	if (list_subtests)
@@ -1462,10 +1470,18 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args)
 		return;
 
 	if (level == IGT_LOG_WARN) {
+		file = stderr;
 		fflush(stdout);
-		vfprintf(stderr, format, args);
-	} else
-		vprintf(format, args);
+	}
+	else
+		file = stdout;
+
+	if (level != IGT_LOG_INFO) {
+		fprintf(file, "(%s:%d) %s%s%s: ", program_invocation_short_name,
+			getpid(), (domain) ? domain : "", (domain) ? "-" : "",
+			igt_log_level_str[level]);
+	}
+	vfprintf(file, format, args);
 }
 
 static void igt_alarm_handler(int signal)
diff --git a/lib/igt_core.h b/lib/igt_core.h
index a258348..5c5ee25 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -512,16 +512,20 @@ bool igt_run_in_simulation(void);
 void igt_skip_on_simulation(void);
 
 /* structured logging */
+#ifndef IGT_LOG_DOMAIN
+#define IGT_LOG_DOMAIN (NULL)
+#endif
+
 enum igt_log_level {
 	IGT_LOG_DEBUG,
 	IGT_LOG_INFO,
 	IGT_LOG_WARN,
 	IGT_LOG_NONE,
 };
-__attribute__((format(printf, 2, 3)))
-void igt_log(enum igt_log_level level, const char *format, ...);
-__attribute__((format(printf, 2, 0)))
-void igt_vlog(enum igt_log_level level, const char *format, va_list args);
+__attribute__((format(printf, 3, 4)))
+void igt_log(const char *domain, enum igt_log_level level, const char *format, ...);
+__attribute__((format(printf, 3, 0)))
+void igt_vlog(const char *domain, enum igt_log_level level, const char *format, va_list args);
 
 /**
  * igt_debug:
@@ -529,7 +533,7 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args);
  *
  * Wrapper for igt_log() for message at the IGT_LOG_DEBUG level.
  */
-#define igt_debug(f...) igt_log(IGT_LOG_DEBUG, f)
+#define igt_debug(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_DEBUG, f)
 
 /**
  * igt_info:
@@ -537,7 +541,7 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args);
  *
  * Wrapper for igt_log() for message at the IGT_LOG_INFO level.
  */
-#define igt_info(f...) igt_log(IGT_LOG_INFO, f)
+#define igt_info(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_INFO, f)
 
 /**
  * igt_warn:
@@ -545,7 +549,7 @@ void igt_vlog(enum igt_log_level level, const char *format, va_list args);
  *
  * Wrapper for igt_log() for message at the IGT_LOG_WARN level.
  */
-#define igt_warn(f...) igt_log(IGT_LOG_WARN, f)
+#define igt_warn(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_WARN, f)
 extern enum igt_log_level igt_log_level;
 
 /**
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 1387d01..042e90e 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -855,7 +855,7 @@ igt_display_log(igt_display_t *display, const char *fmt, ...)
 	igt_debug("display: ");
 	for (i = 0; i < display->log_shift; i++)
 		igt_debug("%s", LOG_SPACES);
-	igt_vlog(IGT_LOG_DEBUG, fmt, args);
+	igt_vlog(IGT_LOG_DOMAIN, IGT_LOG_DEBUG, fmt, args);
 	va_end(args);
 }
 
-- 
2.1.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2014-12-10 17:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-02 17:15 [PATCH i-g-t 1/5] lib: share common logging code Thomas Wood
2014-12-02 17:15 ` [PATCH i-g-t 2/5] tests/gem_tiled_swapping: use igt_info logging wrapper Thomas Wood
2014-12-02 17:15 ` [PATCH i-g-t 3/5] lib: introduce log domains Thomas Wood
2014-12-03 14:22   ` Daniel Vetter
2014-12-04 10:58     ` Thomas Wood
2014-12-10 17:24       ` Thomas Wood [this message]
2014-12-10 17:24         ` [PATCH i-g-t v2 2/2] lib: add optional log domain filtering Thomas Wood
2014-12-02 17:15 ` [PATCH i-g-t 4/5] " Thomas Wood
2014-12-02 17:15 ` [PATCH i-g-t 5/5] lib: write out recent log output if a test fails Thomas Wood

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=1418232248-25565-1-git-send-email-thomas.wood@intel.com \
    --to=thomas.wood@intel.com \
    --cc=intel-gfx@lists.freedesktop.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