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,11 +48,15 @@ static struct spa_log *global_log = &default_log.log;
|
|||
SPA_EXPORT
|
||||
void pw_log_set(struct spa_log *log)
|
||||
{
|
||||
global_log = log;
|
||||
if (global_log)
|
||||
global_log = log ? log : &default_log.log;
|
||||
global_log->level = pw_log_level;
|
||||
}
|
||||
|
||||
bool pw_log_is_default(void)
|
||||
{
|
||||
return global_log == &default_log.log;
|
||||
}
|
||||
|
||||
/** Get the global log interface
|
||||
* \return the global log
|
||||
* \memberof pw_log
|
||||
|
|
@ -71,7 +75,6 @@ SPA_EXPORT
|
|||
void pw_log_set_level(enum spa_log_level level)
|
||||
{
|
||||
pw_log_level = level;
|
||||
if (global_log)
|
||||
global_log->level = level;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,19 +43,26 @@ extern "C" {
|
|||
/** The global 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);
|
||||
|
||||
/** Get the log interface */
|
||||
struct spa_log *pw_log_get(void);
|
||||
|
||||
void
|
||||
pw_log_set_level(enum spa_log_level level);
|
||||
/** Configure the logging level */
|
||||
void pw_log_set_level(enum spa_log_level level);
|
||||
|
||||
|
||||
/** Log a message */
|
||||
void
|
||||
pw_log_log(enum spa_log_level level,
|
||||
const char *file,
|
||||
int line, const char *func,
|
||||
const char *fmt, ...) SPA_PRINTF_FUNC(5, 6);
|
||||
|
||||
/** Log a message */
|
||||
void
|
||||
pw_log_logv(enum spa_log_level level,
|
||||
const char *file,
|
||||
|
|
|
|||
|
|
@ -382,6 +382,7 @@ void pw_init(int *argc, char **argv[])
|
|||
spa_list_init(&global_registry.plugins);
|
||||
support->registry = &global_registry;
|
||||
|
||||
if (pw_log_is_default()) {
|
||||
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");
|
||||
|
|
@ -395,6 +396,10 @@ void pw_init(int *argc, char **argv[])
|
|||
log = add_interface(support, SPA_NAME_SUPPORT_LOG, SPA_TYPE_INTERFACE_Log, &info);
|
||||
if (log)
|
||||
pw_log_set(log);
|
||||
} else {
|
||||
support->support[support->n_support++] =
|
||||
SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_Log, pw_log_get());
|
||||
}
|
||||
|
||||
n_items = 0;
|
||||
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_format(lev,pod) pw_log_object(lev,PW_LOG_OBJECT_POD,pod)
|
||||
|
||||
bool pw_log_is_default(void);
|
||||
|
||||
/** \endcond */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue