diff options
author | Wim Taymans <wtaymans@redhat.com> | 2019-11-19 15:38:09 +0100 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2019-11-19 15:38:09 +0100 |
commit | f92775719afcfcf3ef4a341be669e00c0c2a0bb5 (patch) | |
tree | 20b004c5b0e88b330a2cd40ff138e50e6d90b593 /spa | |
parent | 53f93c2bde096feee9846e0d0166a035a741027c (diff) |
log: make timestamps configurable
Diffstat (limited to 'spa')
-rw-r--r-- | spa/include/spa/support/log.h | 2 | ||||
-rw-r--r-- | spa/plugins/support/logger.c | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/spa/include/spa/support/log.h b/spa/include/spa/support/log.h index 49cbca8b..5007caa4 100644 --- a/spa/include/spa/support/log.h +++ b/spa/include/spa/support/log.h @@ -167,6 +167,8 @@ static inline void spa_log_trace_fp (struct spa_log *l, const char *format, ...) #define SPA_KEY_LOG_COLORS "log.colors" /**< enable colors in the logger */ #define SPA_KEY_LOG_FILE "log.file" /**< log to the specified file instead of * stderr. */ +#define SPA_KEY_LOG_TIMESTAMP "log.timestamp" /**< log timestamps */ + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/plugins/support/logger.c b/spa/plugins/support/logger.c index 0df5b0de..f9197a56 100644 --- a/spa/plugins/support/logger.c +++ b/spa/plugins/support/logger.c @@ -56,6 +56,7 @@ struct impl { unsigned int have_source:1; unsigned int colors:1; + unsigned int timestamp:1; }; static void @@ -90,18 +91,20 @@ impl_log_logv(void *object, vsnprintf(text, sizeof(text), fmt, args); - if (level >= SPA_LOG_LEVEL_DEBUG) { + if (impl->timestamp) { struct timespec now; clock_gettime(CLOCK_MONOTONIC_RAW, &now); size = snprintf(location, sizeof(location), "%s[%s][%09lu.%06lu][%s:%i %s()] %s%s\n", prefix, levels[level], now.tv_sec & 0x1FFFFFFF, now.tv_nsec / 1000, strrchr(file, '/') + 1, line, func, text, suffix); + } else { size = snprintf(location, sizeof(location), "%s[%s][%s:%i %s()] %s%s\n", prefix, levels[level], strrchr(file, '/') + 1, line, func, text, suffix); } + if (SPA_UNLIKELY(do_trace)) { uint32_t index; @@ -259,6 +262,8 @@ impl_init(const struct spa_handle_factory *factory, } if (info) { + if ((str = spa_dict_lookup(info, SPA_KEY_LOG_TIMESTAMP)) != NULL) + this->timestamp = (strcmp(str, "true") == 0 || atoi(str) == 1); if ((str = spa_dict_lookup(info, SPA_KEY_LOG_COLORS)) != NULL) this->colors = (strcmp(str, "true") == 0 || atoi(str) == 1); if ((str = spa_dict_lookup(info, SPA_KEY_LOG_LEVEL)) != NULL) |