summaryrefslogtreecommitdiff
path: root/lib/igt_core.c
diff options
context:
space:
mode:
authorThomas Wood <thomas.wood@intel.com>2014-12-02 10:54:54 +0000
committerThomas Wood <thomas.wood@intel.com>2014-12-11 17:55:15 +0000
commit8161a21762b552d97fe6bde8d4fd441d9cd10f61 (patch)
treeddab7ee124f986af4451508c44890c2ce87bc4c1 /lib/igt_core.c
parent85b74d5c14506bbae53ab02408102645e071a206 (diff)
lib: introduce log domains
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 debug messages. v3: check for glibc before using program_invocation_short_name Signed-off-by: Thomas Wood <thomas.wood@intel.com>
Diffstat (limited to 'lib/igt_core.c')
-rw-r--r--lib/igt_core.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 13a52a5a..b247a03a 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,10 +1451,25 @@ 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 *program_name;
+ const char *igt_log_level_str[] = {
+ "DEBUG",
+ "INFO",
+ "WARNING",
+ "NONE"
+ };
+
assert(format);
+#ifdef __GLIBC__
+ program_name = program_invocation_short_name;
+#else
+ program_name = command_str;
+#endif
+
if (list_subtests)
return;
@@ -1462,10 +1477,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_name, getpid(),
+ (domain) ? domain : "", (domain) ? "-" : "",
+ igt_log_level_str[level]);
+ }
+ vfprintf(file, format, args);
}
static void igt_alarm_handler(int signal)