diff options
author | Wim Taymans <wtaymans@redhat.com> | 2020-04-24 16:20:18 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2020-04-27 11:18:49 +0200 |
commit | 93211549a401084d5626d92b3329118959af8320 (patch) | |
tree | 7f969be319715992b8866afc78bcf17c02ade92d | |
parent | b69bdc1eff2c40fc438dfbe937ea0eea376697fc (diff) |
log: add option to disable line numbers
-rw-r--r-- | spa/include/spa/support/log.h | 1 | ||||
-rw-r--r-- | spa/plugins/support/logger.c | 30 | ||||
-rw-r--r-- | src/pipewire/pipewire.c | 3 |
3 files changed, 22 insertions, 12 deletions
diff --git a/spa/include/spa/support/log.h b/spa/include/spa/support/log.h index c922f036..c97cc8e5 100644 --- a/spa/include/spa/support/log.h +++ b/spa/include/spa/support/log.h @@ -171,6 +171,7 @@ static inline void spa_log_trace_fp (struct spa_log *l, const char *format, ...) #define SPA_KEY_LOG_FILE "log.file" /**< log to the specified file instead of * stderr. */ #define SPA_KEY_LOG_TIMESTAMP "log.timestamp" /**< log timestamps */ +#define SPA_KEY_LOG_LINE "log.line" /**< log file and line numbers */ #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/plugins/support/logger.c b/spa/plugins/support/logger.c index dac57611..91ae2e12 100644 --- a/spa/plugins/support/logger.c +++ b/spa/plugins/support/logger.c @@ -61,6 +61,7 @@ struct impl { unsigned int have_source:1; unsigned int colors:1; unsigned int timestamp:1; + unsigned int line:1; }; static SPA_PRINTF_FUNC(6,0) void @@ -73,10 +74,10 @@ impl_log_logv(void *object, va_list args) { struct impl *impl = object; - char text[512], location[1024]; + char location[1024], *p; static const char *levels[] = { "-", "E", "W", "I", "D", "T", "*T*" }; const char *prefix = "", *suffix = ""; - int size; + int size, len; bool do_trace; if ((do_trace = (level == SPA_LOG_LEVEL_TRACE && impl->have_source))) @@ -93,21 +94,27 @@ impl_log_logv(void *object, suffix = "\x1B[0m"; } - vsnprintf(text, sizeof(text), fmt, args); + p = location; + len = sizeof(location); + + size = snprintf(p, len, "%s[%s]", prefix, levels[level]); if (impl->timestamp) { struct timespec now; clock_gettime(CLOCK_MONOTONIC_RAW, &now); + size += snprintf(p + size, len - size, "[%09lu.%06lu]", + now.tv_sec & 0x1FFFFFFF, now.tv_nsec / 1000); - 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 (impl->line) { + size += snprintf(p + size, len - size, "[%s:%i %s()]", + strrchr(file, '/') + 1, line, func); + } + size += snprintf(p + size, len - size, " "); + size += vsnprintf(p + size, len - size, fmt, args); + if (impl->colors) + size += snprintf(p + size, len - size, "%s\n", suffix); if (SPA_UNLIKELY(do_trace)) { uint32_t index; @@ -256,10 +263,11 @@ impl_init(const struct spa_handle_factory *factory, this->have_source = true; } } - 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_LINE)) != NULL) + this->line = (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) diff --git a/src/pipewire/pipewire.c b/src/pipewire/pipewire.c index 89d66d5b..5b7070c3 100644 --- a/src/pipewire/pipewire.c +++ b/src/pipewire/pipewire.c @@ -356,7 +356,7 @@ SPA_EXPORT void pw_init(int *argc, char **argv[]) { const char *str; - struct spa_dict_item items[4]; + struct spa_dict_item items[5]; uint32_t n_items; struct spa_dict info; struct support *support = &global_support; @@ -385,6 +385,7 @@ void pw_init(int *argc, char **argv[]) n_items = 0; items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_COLORS, "true"); items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_TIMESTAMP, "true"); + items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_LINE, "true"); snprintf(level, sizeof(level), "%d", pw_log_level); items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_LEVEL, level); if ((str = getenv("PIPEWIRE_LOG")) != NULL) |