mirror of https://github.com/mpv-player/mpv
msg: allow duplicating a mp_log
Trivial; this is mostly just reindenting the normal codepath.
This commit is contained in:
parent
95286cd8b8
commit
cae22ae3b6
35
common/msg.c
35
common/msg.c
|
@ -367,34 +367,39 @@ void mp_msg_va(struct mp_log *log, int lev, const char *format, va_list va)
|
||||||
// parent's name. If the name starts with "/", the parent's name is not
|
// parent's name. If the name starts with "/", the parent's name is not
|
||||||
// prefixed (except in verbose mode), and if it starts with "!", the name is
|
// prefixed (except in verbose mode), and if it starts with "!", the name is
|
||||||
// not printed at all (except in verbose mode).
|
// not printed at all (except in verbose mode).
|
||||||
|
// If name is NULL, the parent's name/prefix is used.
|
||||||
// Thread-safety: fully thread-safe, but keep in mind that talloc is not (so
|
// Thread-safety: fully thread-safe, but keep in mind that talloc is not (so
|
||||||
// talloc_ctx must be owned by the current thread).
|
// talloc_ctx must be owned by the current thread).
|
||||||
struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,
|
struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,
|
||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
assert(parent);
|
assert(parent);
|
||||||
assert(name);
|
|
||||||
struct mp_log *log = talloc_zero(talloc_ctx, struct mp_log);
|
struct mp_log *log = talloc_zero(talloc_ctx, struct mp_log);
|
||||||
if (!parent->root)
|
if (!parent->root)
|
||||||
return log; // same as null_log
|
return log; // same as null_log
|
||||||
log->root = parent->root;
|
log->root = parent->root;
|
||||||
if (name[0] == '!') {
|
if (name) {
|
||||||
name = &name[1];
|
if (name[0] == '!') {
|
||||||
} else if (name[0] == '/') {
|
name = &name[1];
|
||||||
name = &name[1];
|
} else if (name[0] == '/') {
|
||||||
log->prefix = talloc_strdup(log, name);
|
name = &name[1];
|
||||||
} else {
|
log->prefix = talloc_strdup(log, name);
|
||||||
log->prefix = parent->prefix
|
} else {
|
||||||
|
log->prefix = parent->prefix
|
||||||
|
? talloc_asprintf(log, "%s/%s", parent->prefix, name)
|
||||||
|
: talloc_strdup(log, name);
|
||||||
|
}
|
||||||
|
log->verbose_prefix = parent->prefix
|
||||||
? talloc_asprintf(log, "%s/%s", parent->prefix, name)
|
? talloc_asprintf(log, "%s/%s", parent->prefix, name)
|
||||||
: talloc_strdup(log, name);
|
: talloc_strdup(log, name);
|
||||||
|
if (log->prefix && !log->prefix[0])
|
||||||
|
log->prefix = NULL;
|
||||||
|
if (!log->verbose_prefix[0])
|
||||||
|
log->verbose_prefix = "global";
|
||||||
|
} else {
|
||||||
|
log->prefix = talloc_strdup(log, parent->prefix);
|
||||||
|
log->verbose_prefix = talloc_strdup(log, parent->verbose_prefix);
|
||||||
}
|
}
|
||||||
log->verbose_prefix = parent->prefix
|
|
||||||
? talloc_asprintf(log, "%s/%s", parent->prefix, name)
|
|
||||||
: talloc_strdup(log, name);
|
|
||||||
if (log->prefix && !log->prefix[0])
|
|
||||||
log->prefix = NULL;
|
|
||||||
if (!log->verbose_prefix[0])
|
|
||||||
log->verbose_prefix = "global";
|
|
||||||
return log;
|
return log;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue