mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
spa: support: remove log pattern support
The log patterns are now handled by plugin host.
This commit is contained in:
parent
dd8d5e1bed
commit
53ba3d0e4c
5 changed files with 1 additions and 144 deletions
|
|
@ -21,8 +21,6 @@
|
||||||
|
|
||||||
#include <systemd/sd-journal.h>
|
#include <systemd/sd-journal.h>
|
||||||
|
|
||||||
#include "log-patterns.h"
|
|
||||||
|
|
||||||
#define NAME "journal"
|
#define NAME "journal"
|
||||||
|
|
||||||
#define DEFAULT_LOG_LEVEL SPA_LOG_LEVEL_INFO
|
#define DEFAULT_LOG_LEVEL SPA_LOG_LEVEL_INFO
|
||||||
|
|
@ -33,8 +31,6 @@ struct impl {
|
||||||
|
|
||||||
/* if non-null, we'll additionally forward all logging to there */
|
/* if non-null, we'll additionally forward all logging to there */
|
||||||
struct spa_log *chain_log;
|
struct spa_log *chain_log;
|
||||||
|
|
||||||
struct spa_list patterns;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static SPA_PRINTF_FUNC(7,0) void
|
static SPA_PRINTF_FUNC(7,0) void
|
||||||
|
|
@ -143,22 +139,12 @@ impl_log_logt(void *object,
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
impl_log_topic_init(void *object, struct spa_log_topic *t)
|
|
||||||
{
|
|
||||||
struct impl *impl = object;
|
|
||||||
enum spa_log_level level = impl->log.level;
|
|
||||||
|
|
||||||
support_log_topic_init(&impl->patterns, level, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct spa_log_methods impl_log = {
|
static const struct spa_log_methods impl_log = {
|
||||||
SPA_VERSION_LOG_METHODS,
|
SPA_VERSION_LOG_METHODS,
|
||||||
.log = impl_log_log,
|
.log = impl_log_log,
|
||||||
.logv = impl_log_logv,
|
.logv = impl_log_logv,
|
||||||
.logt = impl_log_logt,
|
.logt = impl_log_logt,
|
||||||
.logtv = impl_log_logtv,
|
.logtv = impl_log_logtv,
|
||||||
.topic_init = impl_log_topic_init,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
|
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
|
||||||
|
|
@ -180,12 +166,11 @@ static int impl_get_interface(struct spa_handle *handle, const char *type, void
|
||||||
|
|
||||||
static int impl_clear(struct spa_handle *handle)
|
static int impl_clear(struct spa_handle *handle)
|
||||||
{
|
{
|
||||||
struct impl *this;
|
struct impl SPA_UNUSED *this;
|
||||||
|
|
||||||
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
||||||
|
|
||||||
this = (struct impl *) handle;
|
this = (struct impl *) handle;
|
||||||
support_log_free_patterns(&this->patterns);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -251,13 +236,9 @@ impl_init(const struct spa_handle_factory *factory,
|
||||||
&impl_log, impl);
|
&impl_log, impl);
|
||||||
impl->log.level = DEFAULT_LOG_LEVEL;
|
impl->log.level = DEFAULT_LOG_LEVEL;
|
||||||
|
|
||||||
spa_list_init(&impl->patterns);
|
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
if ((str = spa_dict_lookup(info, SPA_KEY_LOG_LEVEL)) != NULL)
|
if ((str = spa_dict_lookup(info, SPA_KEY_LOG_LEVEL)) != NULL)
|
||||||
impl->log.level = atoi(str);
|
impl->log.level = atoi(str);
|
||||||
if ((str = spa_dict_lookup(info, SPA_KEY_LOG_PATTERNS)) != NULL)
|
|
||||||
support_log_parse_patterns(&impl->patterns, str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if our stderr goes to the journal, there's no point in logging both
|
/* if our stderr goes to the journal, there's no point in logging both
|
||||||
|
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
||||||
/* Spa */
|
|
||||||
/* SPDX-FileCopyrightText: Copyright © 2021 Red Hat, Inc. */
|
|
||||||
/* SPDX-License-Identifier: MIT */
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fnmatch.h>
|
|
||||||
|
|
||||||
#include <spa/support/log.h>
|
|
||||||
#include <spa/utils/list.h>
|
|
||||||
#include <spa/utils/json.h>
|
|
||||||
|
|
||||||
#include "log-patterns.h"
|
|
||||||
|
|
||||||
struct support_log_pattern {
|
|
||||||
struct spa_list link;
|
|
||||||
enum spa_log_level level;
|
|
||||||
char pattern[];
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
|
||||||
support_log_topic_init(struct spa_list *patterns, enum spa_log_level default_level,
|
|
||||||
struct spa_log_topic *t)
|
|
||||||
{
|
|
||||||
enum spa_log_level level = default_level;
|
|
||||||
bool has_custom_level = false;
|
|
||||||
const char *topic = t->topic;
|
|
||||||
struct support_log_pattern *pattern;
|
|
||||||
|
|
||||||
spa_list_for_each(pattern, patterns, link) {
|
|
||||||
if (fnmatch(pattern->pattern, topic, 0) != 0)
|
|
||||||
continue;
|
|
||||||
level = pattern->level;
|
|
||||||
has_custom_level = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
t->level = level;
|
|
||||||
t->has_custom_level = has_custom_level;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
support_log_parse_patterns(struct spa_list *patterns, const char *jsonstr)
|
|
||||||
{
|
|
||||||
struct spa_json iter, array, elem;
|
|
||||||
int res = 0;
|
|
||||||
|
|
||||||
spa_json_init(&iter, jsonstr, strlen(jsonstr));
|
|
||||||
|
|
||||||
if (spa_json_enter_array(&iter, &array) < 0)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
while (spa_json_enter_object(&array, &elem) > 0) {
|
|
||||||
char pattern[512] = {0};
|
|
||||||
|
|
||||||
while (spa_json_get_string(&elem, pattern, sizeof(pattern)) > 0) {
|
|
||||||
struct support_log_pattern *p;
|
|
||||||
const char *val;
|
|
||||||
int len;
|
|
||||||
int lvl;
|
|
||||||
|
|
||||||
if ((len = spa_json_next(&elem, &val)) <= 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!spa_json_is_int(val, len))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if ((res = spa_json_parse_int(val, len, &lvl)) < 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
SPA_CLAMP(lvl, SPA_LOG_LEVEL_NONE, SPA_LOG_LEVEL_TRACE);
|
|
||||||
|
|
||||||
p = calloc(1, sizeof(*p) + strlen(pattern) + 1);
|
|
||||||
p->level = lvl;
|
|
||||||
strcpy(p->pattern, pattern);
|
|
||||||
spa_list_append(patterns, &p->link);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
support_log_free_patterns(struct spa_list *patterns)
|
|
||||||
{
|
|
||||||
struct support_log_pattern *p;
|
|
||||||
|
|
||||||
spa_list_consume(p, patterns, link) {
|
|
||||||
spa_list_remove(&p->link);
|
|
||||||
free(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
#ifndef LOG_PATTERNS_H
|
|
||||||
#define LOG_PATTERNS_H
|
|
||||||
|
|
||||||
#include <spa/support/log.h>
|
|
||||||
|
|
||||||
struct spa_list;
|
|
||||||
|
|
||||||
void support_log_topic_init(struct spa_list *patterns, enum spa_log_level default_level,
|
|
||||||
struct spa_log_topic *t);
|
|
||||||
int support_log_parse_patterns(struct spa_list *patterns, const char *jsonstr);
|
|
||||||
void support_log_free_patterns(struct spa_list *patterns);
|
|
||||||
|
|
||||||
#endif /* LOG_PATTERNS_H */
|
|
||||||
|
|
@ -20,8 +20,6 @@
|
||||||
#include <spa/utils/string.h>
|
#include <spa/utils/string.h>
|
||||||
#include <spa/utils/ansi.h>
|
#include <spa/utils/ansi.h>
|
||||||
|
|
||||||
#include "log-patterns.h"
|
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__MidnightBSD__)
|
#if defined(__FreeBSD__) || defined(__MidnightBSD__)
|
||||||
#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
|
#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -48,8 +46,6 @@ struct impl {
|
||||||
unsigned int colors:1;
|
unsigned int colors:1;
|
||||||
unsigned int timestamp:1;
|
unsigned int timestamp:1;
|
||||||
unsigned int line:1;
|
unsigned int line:1;
|
||||||
|
|
||||||
struct spa_list patterns;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static SPA_PRINTF_FUNC(7,0) void
|
static SPA_PRINTF_FUNC(7,0) void
|
||||||
|
|
@ -221,22 +217,12 @@ static void on_trace_event(struct spa_source *source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
impl_log_topic_init(void *object, struct spa_log_topic *t)
|
|
||||||
{
|
|
||||||
struct impl *impl = object;
|
|
||||||
enum spa_log_level level = impl->log.level;
|
|
||||||
|
|
||||||
support_log_topic_init(&impl->patterns, level, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct spa_log_methods impl_log = {
|
static const struct spa_log_methods impl_log = {
|
||||||
SPA_VERSION_LOG_METHODS,
|
SPA_VERSION_LOG_METHODS,
|
||||||
.log = impl_log_log,
|
.log = impl_log_log,
|
||||||
.logv = impl_log_logv,
|
.logv = impl_log_logv,
|
||||||
.logt = impl_log_logt,
|
.logt = impl_log_logt,
|
||||||
.logtv = impl_log_logtv,
|
.logtv = impl_log_logtv,
|
||||||
.topic_init = impl_log_topic_init,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
|
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
|
||||||
|
|
@ -264,8 +250,6 @@ static int impl_clear(struct spa_handle *handle)
|
||||||
|
|
||||||
this = (struct impl *) handle;
|
this = (struct impl *) handle;
|
||||||
|
|
||||||
support_log_free_patterns(&this->patterns);
|
|
||||||
|
|
||||||
if (this->close_file && this->file != NULL)
|
if (this->close_file && this->file != NULL)
|
||||||
fclose(this->file);
|
fclose(this->file);
|
||||||
|
|
||||||
|
|
@ -313,7 +297,6 @@ impl_init(const struct spa_handle_factory *factory,
|
||||||
|
|
||||||
loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Loop);
|
loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Loop);
|
||||||
this->system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_System);
|
this->system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_System);
|
||||||
spa_list_init(&this->patterns);
|
|
||||||
|
|
||||||
if (loop != NULL && this->system != NULL) {
|
if (loop != NULL && this->system != NULL) {
|
||||||
this->source.func = on_trace_event;
|
this->source.func = on_trace_event;
|
||||||
|
|
@ -358,8 +341,6 @@ impl_init(const struct spa_handle_factory *factory,
|
||||||
this->close_file = true;
|
this->close_file = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((str = spa_dict_lookup(info, SPA_KEY_LOG_PATTERNS)) != NULL)
|
|
||||||
support_log_parse_patterns(&this->patterns, str);
|
|
||||||
}
|
}
|
||||||
if (this->file == NULL) {
|
if (this->file == NULL) {
|
||||||
this->file = stderr;
|
this->file = stderr;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
spa_support_sources = [
|
spa_support_sources = [
|
||||||
'cpu.c',
|
'cpu.c',
|
||||||
'logger.c',
|
'logger.c',
|
||||||
'log-patterns.c',
|
|
||||||
'loop.c',
|
'loop.c',
|
||||||
'node-driver.c',
|
'node-driver.c',
|
||||||
'null-audio-sink.c',
|
'null-audio-sink.c',
|
||||||
|
|
@ -56,7 +55,6 @@ endif
|
||||||
if systemd_dep.found()
|
if systemd_dep.found()
|
||||||
spa_journal_sources = [
|
spa_journal_sources = [
|
||||||
'journal.c',
|
'journal.c',
|
||||||
'log-patterns.c',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
spa_journal_lib = shared_library('spa-journal',
|
spa_journal_lib = shared_library('spa-journal',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue