mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
log: add option to set log before pw_init()
Make it possible to call pw_log_set() before pw_init() so that it's used for everything.
This commit is contained in:
parent
13fd6be747
commit
be8263208d
4 changed files with 36 additions and 19 deletions
|
|
@ -48,9 +48,13 @@ static struct spa_log *global_log = &default_log.log;
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
void pw_log_set(struct spa_log *log)
|
void pw_log_set(struct spa_log *log)
|
||||||
{
|
{
|
||||||
global_log = log;
|
global_log = log ? log : &default_log.log;
|
||||||
if (global_log)
|
global_log->level = pw_log_level;
|
||||||
global_log->level = pw_log_level;
|
}
|
||||||
|
|
||||||
|
bool pw_log_is_default(void)
|
||||||
|
{
|
||||||
|
return global_log == &default_log.log;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the global log interface
|
/** Get the global log interface
|
||||||
|
|
@ -71,8 +75,7 @@ SPA_EXPORT
|
||||||
void pw_log_set_level(enum spa_log_level level)
|
void pw_log_set_level(enum spa_log_level level)
|
||||||
{
|
{
|
||||||
pw_log_level = level;
|
pw_log_level = level;
|
||||||
if (global_log)
|
global_log->level = level;
|
||||||
global_log->level = level;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Log a message
|
/** Log a message
|
||||||
|
|
|
||||||
|
|
@ -43,19 +43,26 @@ extern "C" {
|
||||||
/** The global log level */
|
/** The global log level */
|
||||||
extern enum spa_log_level pw_log_level;
|
extern enum spa_log_level pw_log_level;
|
||||||
|
|
||||||
|
/** Configure a logging module. This is usually done automatically
|
||||||
|
* in pw_init() but you can install a custom logger before calling
|
||||||
|
* pw_init(). */
|
||||||
void pw_log_set(struct spa_log *log);
|
void pw_log_set(struct spa_log *log);
|
||||||
|
|
||||||
|
/** Get the log interface */
|
||||||
struct spa_log *pw_log_get(void);
|
struct spa_log *pw_log_get(void);
|
||||||
|
|
||||||
void
|
/** Configure the logging level */
|
||||||
pw_log_set_level(enum spa_log_level level);
|
void pw_log_set_level(enum spa_log_level level);
|
||||||
|
|
||||||
|
|
||||||
|
/** Log a message */
|
||||||
void
|
void
|
||||||
pw_log_log(enum spa_log_level level,
|
pw_log_log(enum spa_log_level level,
|
||||||
const char *file,
|
const char *file,
|
||||||
int line, const char *func,
|
int line, const char *func,
|
||||||
const char *fmt, ...) SPA_PRINTF_FUNC(5, 6);
|
const char *fmt, ...) SPA_PRINTF_FUNC(5, 6);
|
||||||
|
|
||||||
|
/** Log a message */
|
||||||
void
|
void
|
||||||
pw_log_logv(enum spa_log_level level,
|
pw_log_logv(enum spa_log_level level,
|
||||||
const char *file,
|
const char *file,
|
||||||
|
|
|
||||||
|
|
@ -382,19 +382,24 @@ void pw_init(int *argc, char **argv[])
|
||||||
spa_list_init(&global_registry.plugins);
|
spa_list_init(&global_registry.plugins);
|
||||||
support->registry = &global_registry;
|
support->registry = &global_registry;
|
||||||
|
|
||||||
n_items = 0;
|
if (pw_log_is_default()) {
|
||||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_COLORS, "true");
|
n_items = 0;
|
||||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_TIMESTAMP, "true");
|
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_COLORS, "true");
|
||||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_LINE, "true");
|
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_TIMESTAMP, "true");
|
||||||
snprintf(level, sizeof(level), "%d", pw_log_level);
|
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_LINE, "true");
|
||||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_LEVEL, level);
|
snprintf(level, sizeof(level), "%d", pw_log_level);
|
||||||
if ((str = getenv("PIPEWIRE_LOG")) != NULL)
|
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_LEVEL, level);
|
||||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_FILE, str);
|
if ((str = getenv("PIPEWIRE_LOG")) != NULL)
|
||||||
info = SPA_DICT_INIT(items, n_items);
|
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LOG_FILE, str);
|
||||||
|
info = SPA_DICT_INIT(items, n_items);
|
||||||
|
|
||||||
log = add_interface(support, SPA_NAME_SUPPORT_LOG, SPA_TYPE_INTERFACE_Log, &info);
|
log = add_interface(support, SPA_NAME_SUPPORT_LOG, SPA_TYPE_INTERFACE_Log, &info);
|
||||||
if (log)
|
if (log)
|
||||||
pw_log_set(log);
|
pw_log_set(log);
|
||||||
|
} else {
|
||||||
|
support->support[support->n_support++] =
|
||||||
|
SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_Log, pw_log_get());
|
||||||
|
}
|
||||||
|
|
||||||
n_items = 0;
|
n_items = 0;
|
||||||
if ((str = getenv("PIPEWIRE_CPU")))
|
if ((str = getenv("PIPEWIRE_CPU")))
|
||||||
|
|
|
||||||
|
|
@ -1104,6 +1104,8 @@ void pw_log_log_object(enum spa_log_level level, const char *file, int line,
|
||||||
#define pw_log_pod(lev,pod) pw_log_object(lev,PW_LOG_OBJECT_POD,pod)
|
#define pw_log_pod(lev,pod) pw_log_object(lev,PW_LOG_OBJECT_POD,pod)
|
||||||
#define pw_log_format(lev,pod) pw_log_object(lev,PW_LOG_OBJECT_POD,pod)
|
#define pw_log_format(lev,pod) pw_log_object(lev,PW_LOG_OBJECT_POD,pod)
|
||||||
|
|
||||||
|
bool pw_log_is_default(void);
|
||||||
|
|
||||||
/** \endcond */
|
/** \endcond */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue