mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
log: add option to disable line numbers
This commit is contained in:
parent
b69bdc1eff
commit
93211549a4
3 changed files with 22 additions and 12 deletions
|
|
@ -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
|
#define SPA_KEY_LOG_FILE "log.file" /**< log to the specified file instead of
|
||||||
* stderr. */
|
* stderr. */
|
||||||
#define SPA_KEY_LOG_TIMESTAMP "log.timestamp" /**< log timestamps */
|
#define SPA_KEY_LOG_TIMESTAMP "log.timestamp" /**< log timestamps */
|
||||||
|
#define SPA_KEY_LOG_LINE "log.line" /**< log file and line numbers */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ struct impl {
|
||||||
unsigned int have_source:1;
|
unsigned int have_source:1;
|
||||||
unsigned int colors:1;
|
unsigned int colors:1;
|
||||||
unsigned int timestamp:1;
|
unsigned int timestamp:1;
|
||||||
|
unsigned int line:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static SPA_PRINTF_FUNC(6,0) void
|
static SPA_PRINTF_FUNC(6,0) void
|
||||||
|
|
@ -73,10 +74,10 @@ impl_log_logv(void *object,
|
||||||
va_list args)
|
va_list args)
|
||||||
{
|
{
|
||||||
struct impl *impl = object;
|
struct impl *impl = object;
|
||||||
char text[512], location[1024];
|
char location[1024], *p;
|
||||||
static const char *levels[] = { "-", "E", "W", "I", "D", "T", "*T*" };
|
static const char *levels[] = { "-", "E", "W", "I", "D", "T", "*T*" };
|
||||||
const char *prefix = "", *suffix = "";
|
const char *prefix = "", *suffix = "";
|
||||||
int size;
|
int size, len;
|
||||||
bool do_trace;
|
bool do_trace;
|
||||||
|
|
||||||
if ((do_trace = (level == SPA_LOG_LEVEL_TRACE && impl->have_source)))
|
if ((do_trace = (level == SPA_LOG_LEVEL_TRACE && impl->have_source)))
|
||||||
|
|
@ -93,21 +94,27 @@ impl_log_logv(void *object,
|
||||||
suffix = "\x1B[0m";
|
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) {
|
if (impl->timestamp) {
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
clock_gettime(CLOCK_MONOTONIC_RAW, &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)) {
|
if (SPA_UNLIKELY(do_trace)) {
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
|
|
@ -256,10 +263,11 @@ impl_init(const struct spa_handle_factory *factory,
|
||||||
this->have_source = true;
|
this->have_source = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
if ((str = spa_dict_lookup(info, SPA_KEY_LOG_TIMESTAMP)) != NULL)
|
if ((str = spa_dict_lookup(info, SPA_KEY_LOG_TIMESTAMP)) != NULL)
|
||||||
this->timestamp = (strcmp(str, "true") == 0 || atoi(str) == 1);
|
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)
|
if ((str = spa_dict_lookup(info, SPA_KEY_LOG_COLORS)) != NULL)
|
||||||
this->colors = (strcmp(str, "true") == 0 || atoi(str) == 1);
|
this->colors = (strcmp(str, "true") == 0 || atoi(str) == 1);
|
||||||
if ((str = spa_dict_lookup(info, SPA_KEY_LOG_LEVEL)) != NULL)
|
if ((str = spa_dict_lookup(info, SPA_KEY_LOG_LEVEL)) != NULL)
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,7 @@ SPA_EXPORT
|
||||||
void pw_init(int *argc, char **argv[])
|
void pw_init(int *argc, char **argv[])
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
struct spa_dict_item items[4];
|
struct spa_dict_item items[5];
|
||||||
uint32_t n_items;
|
uint32_t n_items;
|
||||||
struct spa_dict info;
|
struct spa_dict info;
|
||||||
struct support *support = &global_support;
|
struct support *support = &global_support;
|
||||||
|
|
@ -385,6 +385,7 @@ void pw_init(int *argc, char **argv[])
|
||||||
n_items = 0;
|
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_COLORS, "true");
|
||||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_TIMESTAMP, "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);
|
snprintf(level, sizeof(level), "%d", pw_log_level);
|
||||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_LEVEL, level);
|
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_LEVEL, level);
|
||||||
if ((str = getenv("PIPEWIRE_LOG")) != NULL)
|
if ((str = getenv("PIPEWIRE_LOG")) != NULL)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue